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::metadata - Adds arbitrary key-value pairs for structured logging.

ยงExamples

use error_rail::{context, location, rail, tag, metadata, ErrorPipeline};

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

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