Module macros

Module macros 

Source
Expand description

Error handling macros for context creation Ergonomic macros for creating lazy or structured ErrorContext.

These macros provide convenient shortcuts for attaching rich metadata to errors:

  • crate::rail - Wraps a Result-producing block and converts it into a BoxedComposableResult via ErrorPipeline::finish.
  • crate::context - Defers formatting until the context is consumed, avoiding unnecessary allocations on the success path.
  • crate::location - Automatically captures the current file path and line number using file!() and line!().
  • crate::tag - Attaches a short categorical label for filtering and searching.
  • crate::group - Creates a lazily-evaluated grouped context that combines multiple fields (message, tags, location, metadata) into one cohesive unit while deferring all formatting until the error occurs.

ยงExamples

use error_rail::{context, rail, group, ErrorPipeline};

let result: Result<(), &str> = Err("failed");
let pipeline = ErrorPipeline::new(result)
    .with_context(context!("user_id: {}", 123))
    .with_context(group!(
        tag("auth"),
        location(file!(), line!()),
        metadata("retry_count", "3")
    ))
    .finish_boxed();

// Equivalent rail! shorthand that also returns a boxed composable result
let _ = rail!({
    Err::<(), &str>("failed")
        .map_err(|err| err)
});