Expand description
Composable, metadata-friendly error handling utilities.
error-rail focuses on three pillars:
- Structured context – enrich any error with layered metadata
using
context!helpers and macros such aslocation!andtag!. - Composable collectors – aggregate successes/failures with the
validationmodule and convert betweenResult,Validation, andComposableErrorviaconvert. - Ergonomic traits/macros – glue traits in
traitsand shortcuts inmacroskeep the API light-weight.
Each submodule re-exports its public surface from here, so consumers can
simply depend on error_rail::* or pick focused pieces as needed.
§Examples
§Basic Error with Context
use error_rail::{ComposableError, ErrorContext, context, location, tag};
let err = ComposableError::new("database connection failed")
.with_context(tag!("db"))
.with_context(location!())
.set_code(500);§Validation Accumulation
use error_rail::validation::Validation;
let v1: Validation<&str, i32> = Validation::Valid(10);
let v2: Validation<&str, i32> = Validation::invalid("error");
let combined: Validation<&str, Vec<i32>> = vec![v1, v2].into_iter().collect();
assert!(combined.is_invalid());§Error Pipeline
use error_rail::{ErrorPipeline, context};
let result = ErrorPipeline::<i32, &str>::new(Err("failed"))
.with_context(context!("operation: load_config"))
.with_context(context!("user_id: 42"))
.finish();
if let Err(err) = result {
eprintln!("{}", err.error_chain());
// Output: user_id: 42 -> operation: load_config -> failed
}Re-exports§
pub use context::*;pub use convert::*;pub use traits::*;pub use types::*;pub use validation::*;
Modules§
- context
- Error context management and accumulation Helpers for attaching rich context metadata to errors.
- convert
- Error type conversions between Result, Validation, and ComposableError
Conversion helpers between
Result,Validation, andComposableError. - macros
- Error handling macros for context creation
Ergonomic macros for creating lazy or structured
ErrorContext. - traits
- Core traits for error handling and composition Core traits for error handling and composition.
- types
- ComposableError and error context structures Error types and utilities.
- validation
- Validation type and associated traits for error accumulation Validation types and utilities for accumulating errors.
Macros§
- backtrace
- Captures the current backtrace as lazy error context.
- context
- Creates a lazily-evaluated error context that defers string formatting.
- impl_
error_ context - Implements
IntoErrorContextfor a custom type. - location
- Captures the current source file and line number as error context.
- metadata
- Creates a key-value metadata pair for structured error context.
- rail
- Wraps a
Result-producing expression or block and converts it into aBoxedComposableResult. - tag
- Creates a categorical tag for error classification.