-
Notifications
You must be signed in to change notification settings - Fork 60
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
Auto-context for simple pass-through errors (like thiserror
)
#276
Comments
There's likely a few errors in that code, but I think the point is apparent. |
You can do that in SNAFU today: #[derive(Debug, Snafu)]
pub enum MyError {
#[snafu(display("Error : {}", source))]
#[snafu(context(false))] // <--- Here
LibraryError { source: LibraryError },
#[snafu(display("Error number: {}, source: {}", number, source))]
AMoreComplicatedError { source: io::Error, number: usize },
} #199 tracks making this work as |
My bad. So |
Also, does it still create the hidden context structs? Thanks! |
That is correct.
It does not. |
Great, thank you! |
I've found that
thiserror
andsnafu
fill two distinct roles for me. In the case when I have complex errors that take extra arguments, SNAFU is fantastic. However, in the case when module errors are simple wrappers around library errors,thiserror
is simpler to use and syntactically tighter. It's also the case that one often gets name collisions with the intermediate structure and the library error, so this doesn't work (which is often frustrating):It occurred to me that the SNAFU could fill both roles if in the simple case, the context could be inferred, much like with
thiserror
. Obviously, this depends on being able to disambiguate it, but that would still include many situations.The solution might even be to include
thiserror
like syntax for pass-through errors:The text was updated successfully, but these errors were encountered: