-
Notifications
You must be signed in to change notification settings - Fork 12
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
Revamp errors #95
Revamp errors #95
Conversation
Thanks for the initial feedback @mara-schulke and @j-baker! This is what I'm going to do next:
The root Error type will have a Open questions:
EDIT: change of plans, now exporting several error types, see comments below for reasoning. |
Your action plan sounds good @asmello 😊 |
I've been doing some further reading on error handling best practices. I think we're on the right track with the dual internally-granular and externally-opaque principles. That said there are some additional things I've been thinking about:
So in addition to the previous plan, I will also work on:
|
Worked on changes today (haven't pushed yet), and as I went through the code again I started to think that granular public errors are not the root of the problem, and not intrinsically a bad thing. The issue James flagged with leaking internal details is extremely valid, but it doesn't mean we should drop error enumeration altogether. I believe it is a fallacy that we should use Here are the actual things we wish to avoid:
To implement a good error system that can evolve fearlessly, it should be sufficient to:
Taking this example from James' comment earlier:
A Locate error here (actually Consider if we instead just mapped this failure mode to an Io variant, we'd have to resort to string matching to distinguish between environment problems and filesystem errors, which have very different solutions. It's easy for a lib to drop type information, impossible for consumers to safely recover it. Another thing, we don't want to directly expose the BTW I like this writeup I found today, it covers a good chunk of good practices. Why I don't think
|
This PR is ready for another round of feedback. |
234c5d3
to
1ea79de
Compare
#[non_exhaustive] | ||
#[allow(missing_docs)] | ||
pub enum ExistsError { | ||
/// could not locate the credentials file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we upercase the doc comments, and lowercase them manually in the wrapping error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc comments are now unified with the error messages, so unfortunately this stylistic conflict is something we have to live with. The alternative is to have duplicative comments and messages like before.
|
||
#[derive(Error, Display, Debug)] | ||
#[non_exhaustive] | ||
#[allow(missing_docs)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one can and should go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not, because if we add a top-level doc-comment it will override the per-variant display implementation. It's another downside of using displaydoc...
ManifestWrite(#[from] manifest::WriteError), | ||
/// failed to create package store | ||
PackageStore(#[from] package::CreateStoreError), | ||
/// {0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a meaningful doc comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all. It's just there to tell displaydoc how to render the Other variant (ie, transparently). I could use #[displaydoc("...")]
to make it possible to additionally include a non-display doc-comment, but I'm not sure what I'd put there.
@jonhoo this is a complex and subtle enough design decision that we'd deeply value your input as well! |
Lets not close this already, i believe further discussion is needed |
Superseded by #103 |
Introducing
thiserror
for producing granular error types everywhere. This is primarily intended to support consuming Buffrs as a library, but also lays the foundations for easily producing better error messages (thinkmiette
and the likes).There's A LOT of code touched by this PR, but the changes should be pretty straightforward. I tried not to make structural changes but some refactoring was unavoidable.