3 ms·
Doing some analysis, "naked" if-err-return-err shows up in about 5% of error handling cases in my team's most critical service. The rest of the error blocks do
by sethammons 5y ago
Doing some analysis, "naked" if-err-return-err shows up in about 5% of error handling cases in my team's most critical service.
The rest of the error blocks do something more (attempt a fallback, add context, log something, metric something, etc). This is code base that has been worked on for about 6 years, around 40k lines of code, 32 contributors, and over 450 releases. This is a legit production mail transfer agent. Take this as an experience report on a real system: that pattern is not as common as you think. 5% is pretty low.
- irq-1 5y agoCurious if there is a one liner that would cover 80%+ of the error handling: onerror add context and return ; onerror function(err) and return ;
- sethammons 5y agoError handling differs. But we try to move up metrics and logs as high as possible in the call chain. Handling an error may be a retry with a strategy, moving items to different queues, changing concurrency, potentially triggering jobs to run, feeding different events to event streams, and, of course, retuning errors to callers so they can programmatically respond.