NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io, #13 most downloaded on crates.io
Implementation detail of the `thiserror` crate
Latest stable
2.0.21
Last release 1 months ago
23 Sep 2026
Release timing varies
gaps range from 8 days to 6 months
Most releases are documented
notes for 53 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
7 years old
91 releases · first in 2019
Drag across the ruler to compare, or tap a release to open it.
Improve diagnostic when there is an enum variant containing #[from] #[backtrace] Error, Backtrace
#[from] #[backtrace] Error, Backtrace (#163)Make #[source] attribute usable on a field of type Box (#155, thanks @cosmicexplorer)
#[source] attribute usable on a field of type Box<dyn Error + Send + Sync + UnwindSafe + 'static> (#155, thanks @cosmicexplorer)Support error types containing generic type parameters (#148, #149, #150, #151)
Support error types containing generic type parameters (#148, #149, #150, #151)
use thiserror::Error;
#[derive(Error, Debug)]
pub enum MyError<E, F, G> {
#[error("thing {0} ({0:?})")]
Variant(E),
#[error("some error")]
Delegate(#[source] SomeError<F>),
#[error("err 0o{val:o}")]
Octal { val: G },
}
In the above example, thiserror would automatically generate the following pair of generic trait impls.
impl<E, F, G> std::error::Error for MyError<E, F, G>
where
SomeError<F>: std::error::Error + 'static,
Self: std::fmt::Debug + std::fmt::Display;
impl<E, F, G> std::fmt::Display for MyError<E, F, G>
where
E: std::fmt::Debug + std::fmt::Display,
G: std::fmt::Octal;
Your coding agent can read these notes before it upgrades. Set up the MCP server →
Make ? work with error types that hold an optional source
? work with error types that hold an optional source (#147)Support forwarding backtrace method to source's backtrace method (#137, #146, thanks @astraw)
Work around bug in Clippy nonstandard_macro_braces lint
Support error(transparent) on errors containing a non-'static inner error
error(transparent) on errors containing a non-'static inner error (#113)Hygiene fixes in generated source method of error types originating inside of a macro definition to unblock https://github.com/rust-lang/rust/pull/806
source method of error types originating inside of a macro definition to unblock https://github.com/rust-lang/rust/pull/80689#issuecomment-781493634 (#121, thanks @Aaron1011)Better diagnostic when putting non-static lifetimes into the source type of an error (#115, #116)
Fix raw identifier fields in format arguments (#108, thanks @ninevra)
Fix raw identifier fields in format arguments (#108, thanks @ninevra)
#[derive(Error, Debug)]
#[error("raw identifier: {r#type}")]
pub struct Error {
r#type: i32,
}
Fix Rust keyword named format arguments (#109)
#[derive(Error, Debug)]
#[error("keyword: {type}", type = 1)]
pub struct Error;
Support capturing backtraces inside of Arc from a From impl, which makes it possible for errors having backtraces to be clonable
Support capturing backtraces inside of Arc from a From impl, which makes it possible for errors having backtraces to be clonable (#102)
use std::backtrace::Backtrace;
use std::sync::Arc;
use thiserror::Error;
#[derive(Error, Debug, Clone)]
#[error("...")]
pub struct ClonableErrorWithBacktrace {
#[from]
source: Inner,
#[backtrace]
backtrace: Arc<Backtrace>,
}
Resolve unused_qualifications lint in generated code
Avoid triggering used_underscore_binding pedantic Clippy lint in generated code of #\[error(transparent)\] attribute
used_underscore_binding pedantic Clippy lint in generated code of #[error(transparent)] attribute (#88)Fix compiler error in some cases when derive(Error) is invoked from inside of a macro_rules macro
Nothing published for this version
Catch misplaced #\[error(transparent)\] attributes (#80, #81)
Improve error message when an error type is missing a Display impl
Avoid triggering deprecation warnings when an error enum has deprecated variants
Fix failure to compile Display impl if a format string contained more than 1 named interpolated variable and a trailing comma, as in #[error("{v1} {v2
#[error("{v1} {v2}",)]Produce a better error message if a #\[source\] or #\[from\] field contains a non-'static lifetime
Ship license files in thiserror-impl subcrate also
Improve parsing of .0 and .var-style format arguments
Improve parsing of .0 and .var-style format arguments (#54)
For example the one here as the argument to the match expression would now be recognized correctly:
#[derive(Error, Debug)]
pub enum MyError {
#[error("{}: {0}", match .1 {
Some(n) => format!("a variant error occurred with n={}", n),
None => format!("there was an empty variant error"),
})]
Variant(String, Option<usize>),
}
Fix bug affecting display attributes of the form #[error("{}", some_expression)] (where the format string is "{}" and nothing else, and the value form
#[error("{}", some_expression)] (where the format string is "{}" and nothing else, and the value formatted is not just one of the fields from the error) #53Nothing published for this version
Support mixing shorthand and non-shorthand format args
Support mixing shorthand and non-shorthand format args (#47)
#[derive(Error, Debug)]
pub enum Error {
#[error("first letter must be lowercase but was {:?}", first_char(.0))]
WrongCase(String),
#[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)]
OutOfBounds { idx: usize, limits: Limits },
}
Add #[error(transparent)] attribute for delegating Error impl to one field (#50)
This is useful for hiding error variants from a library's public error type:
#[derive(Error, Debug)]
#[error(transparent)] // source and Display delegate to ErrorKind
pub struct Error(ErrorKind);
#[derive(Error, Debug)]
/*private*/ enum ErrorKind {
#[error("...")]
E0,
#[error("...")]
E1(#[source] io::Error),
}
And also for enums that need an "anything else" variant; such variants tend not to have their own Display message but just forward through to the underlying error's Display and source:
#[derive(Error, Debug)]
pub enum MyError {
...
#[error(transparent)]
Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error
}
Support Box\ as a #\[source\] (#41, thanks @mathstuf)
Support interpolating Path and PathBuf fields as if they had a Display impl
Support interpolating Path and PathBuf fields as if they had a Display impl
use std::io;
use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("failed to load {1}")]
Read(#[source] io::Error, PathBuf),
}
In previous releases this would fail to compile with:
error[E0277]: `std::path::PathBuf` doesn't implement `std::fmt::Display`
--> src/main.rs:7:13
|
7 | #[error("failed to load {1}")]
| ^^^^^^^^^^^^^^^^^^^^ `std::path::PathBuf` cannot be formatted with the default formatter
Avoid generated variable name collision with an enum member named formatter (#36, thanks @mathstuf)
formatter (#36, thanks @mathstuf)Fix #[error("{v0}")] where an interpolated identifier contains number digits
#[error("{v0}")] where an interpolated identifier contains number digits (#34)Add a #[from] attribute to request an implementation of std::From from your error's source error types, making it easy to build your error via the ? o
Add a #[from] attribute to request an implementation of std::convert::From from your error's source error types, making it easy to build your error via the ? operator.
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
Io(#[from] io::Error),
Json(#[from] serde_json::Error),
Regex(#[from] regex::Error),
Other(#[from] anyhow::Error),
}
We only permit From to be derived from the error's source field, not any arbitrary other field. Notice that this allows #[from] to imply #[source] so you don't need to also specify #[source] explicitly.
The variant must not contain any other fields beyond the source error and possibly a backtrace. A backtrace is captured from within the From impl if there is a field for it.
#[derive(Error, Debug)]
pub enum MyError {
Io {
#[from]
source: io::Error,
backtrace: Backtrace,
},
}
Named fields with the name source are assumed to be the error source and so no longer require an explicit #[source] attribute.
Enum variants now inherit the #[error(...)] attribute from atop the enum if there is one.
use thiserror::Error;
#[derive(Error, Debug)]
#[error("{0}")] // applies to every variant without its own attr
pub enum Error {
Io(io::Error),
Json(serde_json::Error),
Regex(regex::Error),
#[error("unknown error")]
Unknown,
}
Nothing published for this version
One column per quarter.