Hacker News new | ask | show | jobs
by tedsuo 3338 days ago
I totally agree, there's no need to log that you bubbled an error. My recommendation is to have the function that generates the error also log it internally. That way, you don't need to log any returned errors at all, unless you are calling a 3rd party library that can't log it's own error.
1 comments

Error handling, which includes logging the error, should almost always be the responsibility of the caller. Only the caller knows why the call was made, and only the caller knows the impact of the error on what the caller is trying to do.
Exactly.

You run a process that exits with a non-zero code. Is that an error that should be logged? Or just informational? (E.g. `diff`.)

You request an HTTP resource that doesn't exist. Loggable error? Or normal result?

Only the caller knows.

I recommend separating collection from instrumentation. Always instrument at the source, so that you can instrument the flow of your entire application. If the caller decides there is something about the code flow that is worth recording, it can trigger collection of the entire trace.