thiserror

A derive macro for ergonomic, zero-boilerplate custom error types in Rust.

Library
Cargo
v2.0.21
5,584 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
78 /100 Good
Development Activity 76
Maintenance 84
Community 52
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 85
Code Quality 90
Innovation 88
Learning Curve 88

thiserror is a lightweight derive macro that implements Rust’s std::error::Error trait for custom error types, eliminating the boilerplate of hand-written Display and source() implementations. Developers annotate an enum or struct with #[derive(Error)] and per-variant #[error(”…”)] messages, and thiserror generates the trait implementations at compile time with no runtime cost and no trace left in the crate’s public API.

Widely regarded as the standard choice for library authors who want precise, structured error types (as opposed to anyhow’s single dynamic error type for application code), thiserror is used throughout the Rust ecosystem by crates that need typed, matchable error enums with readable messages.

What You Get

  • A #[derive(Error, Debug)] macro that implements std::error::Error for any struct or enum
  • Automatic Display generation via #[error(”…”)] message strings with field interpolation shorthand ({field}, {0}, {field:?})
  • Automatic From impls for variants annotated with #[from], enabling seamless ? operator conversions
  • source() chaining via #[source] or #[from] fields, plus Backtrace capture via #[backtrace] on nightly compilers
  • #[error(transparent)] support for forwarding Display/source straight through to an inner error, useful for opaque public error types

Common Use Cases

  • Defining a library’s public error enum with one variant per failure mode and a human-readable message per variant
  • Wrapping upstream errors (io::Error, serde_json::Error, etc.) with #[from] for seamless ? propagation across module boundaries
  • Building an opaque top-level error type via #[error(transparent)] to hide internal representation from callers while keeping it free to evolve

Under The Hood

Architecture — The project splits into two crates: the public thiserror crate (src/lib.rs) re-exports a single derive macro and a handful of small runtime helper modules (private.rs, var.rs, aserror.rs, display.rs, provide.rs) that generated code relies on for trait-bound checks and provide() support, while the actual codegen lives in the thiserror-impl proc-macro crate (impl/): ast.rs parses the struct/enum into an internal model, attr.rs parses the #[error(…)], #[from], #[source], #[backtrace] attributes, fmt.rs implements the field-interpolation shorthand parser, valid.rs enforces macro-usage constraints at compile time, and expand.rs assembles the final Display/Error/From token streams. build.rs probes the active compiler version to conditionally enable nightly-only Backtrace/provide() features.

Tech Stack — Pure Rust, 2021 edition, MSRV 1.71. The impl crate depends on the standard proc-macro trio (syn, quote, proc-macro2); the public thiserror crate itself has zero runtime dependencies beyond thiserror-impl, keeping compile times and dependency trees minimal. Dual-licensed MIT OR Apache-2.0. Structured as a Cargo workspace with impl/ and tests/no-std/ as members.

Code Quality — Backed by an extensive test suite: unit-style integration tests (test_display.rs, test_from.rs, test_source.rs, test_transparent.rs, test_backtrace.rs, test_generics.rs, test_option.rs, test_path.rs, test_expr.rs, test_lints.rs) plus a 76-file trybuild tests/ui/ suite that asserts the macro’s compile-error messages stay stable and helpful. Clippy lint allowances are explicitly documented rather than silently suppressed. Over 800 commits and a decorated release history (89 releases) reflect long-term maintenance discipline from a single primary maintainer (dtolnay).

API Design — The public surface is intentionally minimal: one derive macro plus a small set of attributes (#[error], #[from], #[source], #[backtrace]). The field-interpolation shorthand (#[error(“{field}”)] instead of write!(”{}”, self.field)) removes nearly all boilerplate from the common case, and the README explicitly contrasts thiserror against anyhow to help users pick the right tool. Because generated code never appears in the crate’s public API, switching to or away from thiserror is a non-breaking change for consumers.

Used by 58 apps in this directory

TypeScript
78%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,733

Open-source AI agent monitoring that catches what will break next before your users do.

View details
87
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 78%
Python 11%
Rust 11%
Updated 6 days ago
Rust
84%
Apache 2.0

liteparse

Developer Tools

12,906

A fast, lightweight, open-source document parser that extracts spatial text, bounding boxes, and Markdown from PDFs and Office files — entirely on your machine.

View details
83
Repo Health
80
Technical
71
Dependency
Built with
Rust 84%
Updated 1 weeks ago
Dart
79%
Apache 2.0

LocalSend

Networking

95,370

An open-source, cross-platform AirDrop alternative that sends files and messages device-to-device over your local network with no internet, no account, and no cloud server involved.

View details
88
Repo Health
61
Technical
78
Dependency
Built with
Dart 79%
Rust 17%
Updated 1 weeks ago
JavaScript
55%
Other

Lokus

Knowledge Management · Note Taking

829

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
75
Repo Health
75
Technical
64
Dependency
Built with
JavaScript 55%
HTML 21%
Rust 12%
Updated 2 months ago
Rust
59%
Apache 2.0

magika

Developer Tools · Security

18,740

AI-powered file type detection that identifies 200+ content types with ~99% accuracy in milliseconds using a compact deep learning model.

View details
85
Repo Health
85
Technical
74
Dependency
Built with
Rust 59%
YARA 12%
Python 10%
Updated 6 days ago
Rust
60%
Apache 2.0

Magnitude

AI Development · Developer Tools

7,313

An open source inference engine that profiles your hardware, recommends the best local models, and tunes them for the coding agent you already use.

View details
79
Repo Health
83
Technical
71
Dependency
Built with
Rust 60%
TypeScript 25%
Updated 5 days ago
TypeScript
92%
Apache 2.0

Apache Maka

AI Agents · AI Development · Developer Tools

5,868

An Apache-incubated agent workspace that treats every model call, tool run, and permission decision as an append-only, replayable event log instead of disposable chat history.

View details
82
Repo Health
85
Technical
73
Dependency
Built with
TypeScript 92%
Updated 5 days ago
Rust
48%
MIT

Meetily

AI Assistants · Productivity

32,103

Privacy-first AI meeting assistant that transcribes and summarizes your meetings entirely on your local machine — no cloud, no data leakage.

View details
87
Repo Health
72
Technical
67
Dependency
Built with
Rust 48%
TypeScript 29%
Updated 6 days ago
Rust
100%
Other

Meilisearch

Search

59,644

Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.

View details
90
Repo Health
88
Technical
67
Dependency
Built with
Rust 100%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers