Releases: dtolnay/thiserror
Releases · dtolnay/thiserror
1.0.13
1.0.12
1.0.11
1.0.10
-
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>), }
1.0.9
1.0.8
1.0.7
-
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 }
1.0.6
1.0.5
-
Support interpolating
Path
andPathBuf
fields as if they had a Display impluse 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