6 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
This article critiques current error handling practices in Rust, highlighting issues like error forwarding and poor contextual information. It advocates for designing errors with purpose, emphasizing the need for clear, actionable error types for machines and rich context for human debugging.
If you do, here's more
The article critiques common error handling practices in programming, particularly in Rust, highlighting the flaws in how errors are managed and communicated. Many developers treat errors as something to be quickly passed up the stack, losing critical context along the way. The standard `std::error::Error` trait offers limited insights, as it only presents a single chain of causality, which isn't sufficient for complex failures that can involve multiple sources. Additionally, Rustβs backtraces are often misleading and resource-intensive, making them ineffective for diagnosing issues in asynchronous code.
The piece also addresses the pitfalls of the Provider API and popular libraries like `thiserror` and `anyhow`. The Provider API adds unnecessary complexity by introducing dynamic data access to errors, resulting in unpredictable behavior. `thiserror` categorizes errors by their origin, not by actionable responses, leaving developers uncertain about how to handle them. Meanwhile, `anyhow` simplifies error propagation but sacrifices context, making it easy to overlook important details when debugging.
For effective error handling, the article proposes a dual approach tailored to machines and humans. Errors for machine processing should be straightforward and categorized by response types, enabling clear actions like retries without unnecessary complexity. Conversely, human-readable errors should provide rich context, tracing back through the call path and offering detailed information. The `exn` library exemplifies this with its automatic source location capture and ergonomic context addition, ensuring that developers are encouraged to include necessary context without friction. By focusing on how errors should inform actions and debugging, the article advocates for a more thoughtful design of error handling in software development.
Questions about this article
No questions yet.