error-concept
thiserror: transparent wrappers
Use an opaque wrapper when the inner error already has the desired message. A transparent wrapper delegates formatting and source behavior, rather than adding a new diagnostic layer. Requires thiserror = "=2.0.12" in Cargo.toml. See the staged dependency project. Expected stdout (not executed): invalid plan Expected stderr: (empty) Expected exit: success Common mistake: Assuming transparent adds an operation message to the chain.
Formal Syntax & Structure
rust syntaxrust
#[error(transparent)]Working Example
Example Snippetrust
#[derive(Debug, thiserror::Error)]#[error("invalid plan")]struct Inner;#[derive(Debug, thiserror::Error)]#[error(transparent)]struct PlanError(#[from] Inner);fn main() { let error = PlanError::from(Inner); println!("{error}");}