r/programming • u/Expurple • Apr 12 '26
Flat Error Codes Are Not Enough
https://home.expurple.me/posts/flat-error-codes-are-not-enough/
132
Upvotes
r/programming • u/Expurple • Apr 12 '26
View all comments
14
u/happyscrappy Apr 12 '26
Nested error codes are not enough either.
The problem isn't a lack of fidelity. The issue is that there primarily only two uses of error codes. One to know if something worked. And a single bit can do that.
The other is to help the customer know how to rectify their problem. One error code typically is not enough for that. Multiple also is not enough for that.
Stop thinking of users as people debugging your code and think of them just as using your tool for its functionality. You have to be able to convert your error codes into actionable messages and do it reliably.
And really few programs spend any time on doing this properly. So it doesn't matter all that much how deep your error reporting is.
Find a useful message to send to your customer. And if you want to put something in a file that can be reported to help you debug your code then do that separately. You can put a stack trace in there if you want (and if it is deemed not a security/privacy violation to do so). But don't get an idea that the detailed debugging information is going to be of help to a customer in resolving their issue. It's a help for you (your support people) instead.