Module thiserror
Tools for defining custom error types.
- Crate
::thiserror. - docs.rs
- crates.io
- GitHub
thiserror provides derive macros for creating custom error types
that implement std::error::Error with minimal boilerplate.
While anyhow is ideal for applications that need flexible error handling,
thiserror is designed for libraries that want to provide
specific, well-typed errors that callers can match on and handle precisely.
The Error derive macro automatically implements std::error::Error,
Display, and optionally From conversions.
It supports error source chaining, custom display messages,
and transparent delegation to underlying errors.
Key features include #[error("...")] for custom display messages,
#[source] for error source chaining,
#[from] for automatic From implementations.
Examples
Define a custom error type with automatic std::error::Error implementation: