Error management

ErrorThis links to official Rust documentation creation, propagation, and handling in Rust can sometimes feel like it's lacking, especially in older Rust versions. Some crates exist to help you deal with error handling in Rust.

Crate Name Maintenance Status Description
Cargo vec.svganyhow Actively maintained Provides a struct Error, which is a wrapper around a Box<dyn Error>. Adds additional functionality such as backtraces and easy to use addition of context to the error. anyhow::Result<T> can be used as a default return type so that ? propagation is easier. Built to work with thiserror. Suitable for quick prototyping and binaries.
Cargo vec.svgerr-derive
Cargo vec.svgerror-chain Maintained Adds a macro error_chain! to help you create custom error structs that implement std::error::Error
Cargo vec.svgeyre Actively maintained Fork of anyhow that exports a customizable version of anyhow::Error as eyre::Report for storing context relevant to error reports, such as backtraces, outside of the chain of errors and for defining custom report formats. See Cargo vec.svgcolor-eyre for an example of a custom EyreHandler that captures SpanTraces and Backtraces on stable and pretty prints them.
Cargo vec.svgfailure Deprecated[1] Failure provided its own error trait which was incompatible with std's, and so is now deprecated. Anyhow and thiserror provide all the functionality of failure but are compatible with std.
Cargo vec.svgfehler Actively maintained Add support for "throwing functions" to Rust through procedural macros.
Cargo vec.svgproc-macro-error Passively maintained Adds easy ways to produce nice compiler errors from proc macros, instead of having the unhelpful default panic message.
Cargo vec.svgquick-error
Cargo vec.svgsnafu
Cargo vec.svgthiserror Actively maintained Adds a #[derive(Error)] proc macro to help you implement std::error::Error less verbosely. Built to work with anyhow.

See alsoEdit