Hasty Briefsbeta

Ergonomic errors in Rust: write fast, debug with ease, handle precisely

2 days ago
  • #stackerror
  • #Error Handling
  • #Rust
  • Errors in Rust appear in three contexts: writing code, debugging, and runtime handling.
  • stackerror is designed to simplify error handling across all contexts, providing debugging context and structured error codes.
  • Existing Rust error handling tools like bare Result<T, &'static str>, anyhow, and thiserror have trade-offs in context richness, propagation ease, and runtime handling.
  • stackerror combines the ease of anyhow with the precision of thiserror, using error codes for runtime matching and stacked context for debugging.
  • Error handling with stackerror involves minimal boilerplate, rich context stacking, and structured error codes for control flow.
  • The article demonstrates stackerror's features through a practical example involving IO, HTTP handling, and retries.
  • stackerror supports creating library-specific error types with custom error codes, maintaining stable APIs while evolving error messages.
  • The separation of error codes for runtime handling and human-readable messages for debugging ensures precise control flow without exposing internal details.