4 ms·
Always remember the context of your code. All code is ultimately used by other humans, so we should make it convenient for them, depending on how will they use
by bheadmaster 4y ago
Always remember the context of your code. All code is ultimately used by other humans, so we should make it convenient for them, depending on how will they use it.
Are you writing a library? Make it convenient for the user to handle errors - in a way that is consistent with the language. E.g. in Go, return an error. In Python, raise an exception.
Are you writing a CLI program? Print to stderr, and abort program if execution cannot be safely continued.
Are you writing a GUI program? Create an error dialog box, and abort program if execution cannot be safely continued.
Are you writing a web service? Return the appropriate error code (or the equivalent in whatever protocol you use) and a human-readable error message about what happened.
Et cetera.
- thund 4y agoalso don’t be shy: * without disclosing sensitive info, add details to error messages * where possible make errors actionable, eg hint at solutions
- EvanAnderson 4y agoStrong agreement. As a long-time sysadmin I despise "shy" error messages. Don't make me break out strace / Process Monitor / etc to figure out what specific file your generic "File not found" message is referring to.
- ryandrake 4y agoOr, the currently fashionable, yet maddeningly useless: "Something went wrong" with no other explanation. Thanks, error message writer, for absolutely nothing.
- e-clinton 4y agoReally? I’ve always felt like too much detail could further empower a potential attacker.
- EvanAnderson 4y agoI would concede that there is a distinction between error messages meant for the general public vs. sysadmins. Make sure the log the sysadmin sees has actionable information in it, please!
- blooalien 4y agoI've always felt that user-facing error messages should be simple, clear, to-the-point, and should include a simple explanation how to contact the author, and where to find and send any relevant "user-local" log information which might be helpful.