dtolnay/thiserror

derive(Error) for struct and enum error types

View on GitHub ↗Jump to charts ↓

Summary Information

Updated 58 minutes ago
Added to GitGenius on September 12th, 2026
Created on October 9th, 2019
Open Issues & Pull Requests: 32 (+0)
GitHub issues: Enabled
Number of forks: 213
Total Stargazers: 5,542 (+0)
Total Subscribers: 23 (+0)

Repository Insights (GitGenius)

Most active contributors

Sign in to see contributor activity.

Related repositories by overlapping contributors

No overlapping-contributor repos identified yet.

Charts & Analytics

Fetching additional details & charts...

Issue Activity (beta)

Issue API getrepoissuespagesummary failed: 429 Rate limit exceeded. Please try again later.

Detailed Description

thiserror is a derive macro for implementing the standard library's std::error::Error trait in Rust.

The library solves the boilerplate problem of manually implementing Error for custom error types. Instead of writing Display and Error trait implementations by hand, developers annotate their struct or enum with derive(Error) and use attributes like #[error("...")] to specify error messages. The macro generates the Display impl, From impls for error conversion, and source() method implementations automatically. Field interpolation is supported through shorthand syntax that works with format specifiers.

Adopt thiserror if you are building a Rust library or application that defines custom error types and wants to reduce implementation overhead. It suits any project using error enums or structs that need to implement the Error trait. The tool is designed to be transparent—it does not appear in your public API, so switching between handwritten implementations and thiserror is not a breaking change. The macro handles errors as enums, structs with named fields, tuple structs, or unit structs, and supports advanced features like backtrace capture and error source chaining through the #[source] and #[from] attributes.

The project maintains a stable, focused scope with consistent attention to correctness and compatibility. Development activity shows regular updates addressing edge cases and maintaining alignment with Rust language evolution, particularly around backtrace support on nightly compilers. The codebase demonstrates careful handling of the derive macro implementation to ensure generated code is efficient and correct across different error type shapes.