Rust Error Handling
Written
eyre
is a fork ofanyhow
focused on better error reporting- Snafu
- This is a comprehensive library with a lot of options. The big advantage here is that a lot of care is taken to make rich context information easy to use.
-
- This generates an
ErrorType
structure that can be used to add content to anAnError
error.ErrorType
contains everything except the source and backtrace fields. This can then be used with the context trait.- The context type also uses generics parameterized with
Into<OriginalType>
, so you don't have to do things liketo_string()
all over the place.
- The context type also uses generics parameterized with
do_it_or_anerror().context(ErrorType{ operation: "doing it" })
- Source fields can be mapped using
#[snafu(source(from(ErrorType, MapFunc)))]
- Applications may want to enable the
backtraces-impl-backtrace-crate
feature to capture backtraces. Theunstable-backtraces-impl-std
feature does the same for Rust's built-in backtraces, but those aren't stabilized yet. - The
futures
feature adds context methods to futures and streams that return Results.