Structured Errors in Rust: Weighing the Tradeoffs

2025-06-01

This article explores the advantages and disadvantages of using structured errors (e.g., with `thiserror`) versus `anyhow` in Rust applications. Based on experience maintaining a large Rust web server, the author argues that custom error types, while increasing code and maintenance overhead, offer significant benefits: clearly showing all potential failure modes of a function, improving code readability and review; creating more descriptive interfaces; avoiding redundant error messages; enforcing context addition; and allowing for extra data and functionality. However, drawbacks include increased code volume, naming challenges, maintenance overhead, and potential performance concerns. The author concludes that the trade-off should be assessed case-by-case, suggesting that in large applications, the advantages of structured errors may outweigh the costs.

Development