Composable Error Types with `thiserror` in Rust
`thiserror` generates boilerplate for custom Rust error types, letting you define specific, matchable errors for a library. Use it when callers need to handle different failure modes. The footgun is using it for simple app errors where `anyhow` would suffice.
`thiserror` is a Rust macro that generates boilerplate for custom error types. It lets you define structured, composable error enums for a library, making your error-handling code declarative and clean. It's ideal when callers need to `match` on specific failure modes, like `DataStoreError::Disconnect` vs. `DataStoreError::Redaction`. The footgun is confusing its role with `anyhow`: `thiserror` defines library errors, `anyhow` handles application errors.
Read the original → docs.rs
- #rust
- #errors
- #libraries
- #thiserror
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.