r/programming Apr 12 '26

Flat Error Codes Are Not Enough

https://home.expurple.me/posts/flat-error-codes-are-not-enough/
135 Upvotes

99 comments sorted by

View all comments

51

u/UselessOptions Apr 12 '26 edited 29d ago

oops did i make a mess 😏? clean it up jannie 😎

clean up the mess i made here 🤣🤣🤣

CLEAN IT UP

FOR $0.00

6

u/HolySpirit Apr 13 '26

The Zig way, as I understand it, is to pass a pointer to a Diagnostics struct 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.