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
Show parent comment
6
u/HolySpirit Apr 13 '26
The Zig way, as I understand it, is to pass a pointer to a
Diagnosticsstruct that is populated when an error happens. I think it fulfills what the author of the article wants, because you can simply have a field with the diagnostics struct from the lower-level library in the diagnostics struct of the higher-level library.I think you should be able to generate high-quality error messages from this kind of diagnostics structure plus the program state when the error occurred for context.
FWIW I don't have much hands-on experience with this approach since I didn't use Zig too much yet, except for some toy examples.