-
Notifications
You must be signed in to change notification settings - Fork 66
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
Structural conversion from anyhow errors #127
base: master
Are you sure you want to change the base?
Conversation
Adds a more flexible method to construct reports, which will allow things such as providing an explicit backtrace, using a local eyre hook, etc.
the main rough edge to watch out for is accidentally using you might be able to catch these at runtime with debug asserts inside of the eyre hook when converting to a report, by inspecting the |
Yes, this is a footgun and unfortunately as far as I can tell a limitation with Rust. For reference we discussed this a bit yesterday, and while the Something we could do, is try and rethink the Any ideas are highly welcome ❤️ |
Some further consideration and ideas regarding this:
|
My preference is 1 & 2 |
I'm of the same mind as Jane, 1+2 sounds best. I think there's a compromise with 3. We could, in theory, publish a non-default lint that checks for usage of ? or into() where into_eyre() is also possible. That way folks who do care about not losing context have that option while the general case stays flexible and nondisruptive. |
This implements a structural conversion to convert betwen other errors kinds and eyre Reports.
This allows richer error types to provide more context to the eyre report, such as anyhow by preserving backtrace and other context where possible.
This does not apply for anyhow, but future crates as well by implementing
IntoEyreReport
. This can also be used to provide a conversion from a custom error type or enum which contains aReport
that does not nest the Report within a new report, but flattens it which ensures the spantrace and backtrace are forwarded instead of being debug printed without structure inside another backtrace, which can be very confusing.This is an issue I've had with flax, where the library error enum has a variant for a boxed user error, as well as concrete error variants. I wanted to avoid nesting a
eyre::Report
orBox<dyn Error>
inside another Report if a user wraps flax's error themselves.Resolves: #65 (comment)
Resolves: #31