Crate erract

Crate erract 

Source
Expand description

§erract - Structured Error Handling for Rust

erract provides production-ready error handling that solves real problems:

  • Actionable errors: Categorized by what callers can do (retry, fail, etc.)
  • Explicit retry semantics: No guessing from error messages
  • Rich context: Automatic location capture with zero overhead
  • Type safety: Enforce context at module boundaries

§Philosophy

Two audiences, two needs:

  • Machines: Need flat structures, clear error kinds, predictable codes
  • Humans: Need rich context, call paths, business-level information

This library combines the best ideas from:

§Quick Start

use erract::prelude::*;

fn process_user(id: u32) -> erract::Result<String> {
    let error = || Error::permanent(
        ErrorKind::NotFound,
        format!("user not found: {}", id),
    );

    lookup_user(id)
        .or_raise(error)?
        .ok_or_else(|| {
            Error::permanent(
                ErrorKind::NotFound,
                "user not found".to_string(),
            ).raise()
        })
}

fn lookup_user(id: u32) -> erract::Result<Option<String>> {
    Ok(None)
}

§Features

  • Zero runtime overhead: Uses #[track_caller] instead of expensive backtraces
  • Domain-specific errors: HTTP, Database, and Storage error kinds
  • Error trees: Support for multiple concurrent failures
  • Type safety: Compiler enforces context at module boundaries

Re-exports§

pub use crate::context::AddContext;
pub use crate::error::Error;
pub use crate::error::ErrorBuilder;
pub use crate::extract::count_errors;
pub use crate::extract::count_frames;
pub use crate::extract::has_permanent;
pub use crate::extract::has_retryable;
pub use crate::extract::is_all_retryable;
pub use crate::kind::ErrorKind;
pub use crate::status::ErrorStatus;
pub use exn;

Modules§

arena
Arena-based memory management for error context. Arena-based memory management for error context.
context
Context utilities for adding key-value pairs to errors.
convert
Conversions from standard library error types.
db
Database-specific error kinds.
error
Core error type and builders.
extract
Error tree traversal utilities.
http
HTTP-specific error kinds.
kind
Domain-specific error kinds categorized by action.
prelude
Common imports for using erract. Common imports for using erract.
status
Explicit retry semantics for errors.
storage
Storage-specific error kinds.

Functions§

ok
Equivalent to Ok::<_, Exn<Error>>(value).

Type Aliases§

Result
Result type using exn::Exn<Error> as the error type