A context-aware error-handling library for Rust
error-stack is a context-aware error-handling library for Rust that supports arbitrary attached user data. It gives you a Report type that accumulates context as errors propagate, so traces carry the detail you actually need to debug a failure rather than a lossy message.
The crate is published on crates.io at error-stack.
cargo add error-stack
Or add it to your Cargo.toml manually:
[dependencies]
error-stack = "0.5"
error-stack provides a Report type and the ResultExt extension trait, which together let you convert foreign errors into your own error type while preserving — and enriching — the chain of context:
use error_stack::{Report, ResultExt};
#[derive(Debug, thiserror::Error)]
#[error("failed to parse config")]
struct ParseConfigError;
fn parse_config(path: &str) -> Result<String, Report<ParseConfigError>> {
std::fs::read_to_string(path)
.change_context(ParseConfigError)
.attach_printable_lazy(|| format!("reading {path}"))
}
For the full API surface — including Context, attach, Frame inspection, and the feature flags that gate optional integrations — see the crate documentation on docs.rs.