-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate content vs presentation for error types (need render method) #7865
Comments
@bburdette Hi, haven't seen you in a while, but might you want to tackle this sort of thing? |
@Ericson2314 are you suggesting to store a richer representation of what's in the format string, or to render it last-minute based on exception-specific fields, or both? |
@roberth I think just the latter? If we just have the It may be nice to also make all errors structured like GHC is in the process of doing, but I don't feel so urgent about that / it's a fine follow-up projec to this week if we are interested. |
This sounds interesting; perhaps a bit beyond the budget of nix-errors-enhancement right now. But maybe at some point? Do you have some examples of projects that depend on structured errors? |
Sure, sounds good. Maybe I'll start something can then the baton can be passed to you at some later point.
It's been nagging me for a while, but #7788 is what compelled me to write this issue. As you can see it is awkward writing the structured errors today. |
Triaged in the Nix team meeting:
|
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-02-24-nix-team-meeting-minutes-35/25757/1 |
Problem
Current our error infrastructure (
Error
and subclasses) store a format string. This is fine for one off ad-hoc errors, but a problem for structured errors. Those structured errors have various fields (so when caught data can be manipulated without having to parse a string), and those fields duplicate the information stored in the format string.It also makes awkward attempts to display in the information in other ways, such as with JSON logging (where we might want to display the fields in an object, rather than just give the machine-unfriendly format string).
Solution
We really ought have a separate virtual method for rendering errors. Ad-hoc errors can still store the format string like today, and their render implementation would just display it. However structured errors would forego storing a format string entirely, and just do any string formatting that is needed on the fly as part of the render implementation.
This is much clearer, and makes structured errors (which we should encourage!) easier to use.
The text was updated successfully, but these errors were encountered: