Crate error_rail

Crate error_rail 

Source
Expand description

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, group};

let err = ComposableError::new("database connection failed")
    .with_context(group!(
        tag("db"),
        metadata("retry_count", "3")
    ))
    .set_code(500);

assert!(err.to_string().contains("database connection failed"));
assert_eq!(err.error_code(), Some(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_boxed();

if let Err(err) = result {
    let chain = err.error_chain();
    assert!(chain.contains("user_id: 42"));
    assert!(chain.contains("operation: load_config"));
    assert!(chain.contains("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, and ComposableError.
macros
Error handling macros for context creation Ergonomic macros for creating lazy or structured ErrorContext.
prelude
Convenience re-exports for quick starts Convenience re-exports for common usage patterns.
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.
backtrace_force
Creates a backtrace context that always captures regardless of environment.
context
Creates a lazily-evaluated error context that defers string formatting.
group
Creates a grouped error context that combines multiple context types.
impl_error_context
Implements IntoErrorContext for a custom type.
locationDeprecated
Captures the current source file and line number as error context.
metadataDeprecated
Creates a key-value metadata pair for structured error context.
rail
Wraps a Result-producing expression or block and converts it into a BoxedComposableResult.
rail_unboxed
Wraps a Result-producing expression or block and converts it into an unboxed ComposableResult.
tagDeprecated
Creates a categorical tag for error classification.