Skip to main content

ErrorWith

Trait ErrorWith 

Source
pub trait ErrorWith {
    // Required methods
    fn position<S: Into<String>>(self, desc: S) -> Self;
    fn with_context<C: Into<OperationContext>>(self, ctx: C) -> Self;

    // Provided methods
    fn doing<S: Into<String>>(self, desc: S) -> Self
       where Self: Sized { ... }
    fn at<C: Into<OperationContext>>(self, ctx: C) -> Self
       where Self: Sized { ... }
}
Expand description

Extension methods for attaching operation context and position to an error.

doing("...") and at("...") are the primary ways to annotate where and what was happening when the error occurred.

Implemented for StructError and Result<T, E> where E: ErrorWith.

§Example

use orion_error::prelude::*;
use orion_error::UnifiedReason;

let err = StructError::from(UnifiedReason::validation_error())
    .doing("parse config")      // what operation
    .at("config.toml");          // what resource

assert_eq!(err.action_main().as_deref(), Some("parse config"));
assert_eq!(err.locator_main().as_deref(), Some("config.toml"));

// doing/at also works on Result chains:
let result: Result<(), StructError<UnifiedReason>> =
    Err(StructError::from(UnifiedReason::validation_error()))
        .doing("validate")
        .at("input.json");
assert!(result.is_err());

Required Methods§

Source

fn position<S: Into<String>>(self, desc: S) -> Self

Source

fn with_context<C: Into<OperationContext>>(self, ctx: C) -> Self

Provided Methods§

Source

fn doing<S: Into<String>>(self, desc: S) -> Self
where Self: Sized,

Source

fn at<C: Into<OperationContext>>(self, ctx: C) -> Self
where Self: Sized,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, E: ErrorWith> ErrorWith for Result<T, E>

Source§

fn position<S: Into<String>>(self, desc: S) -> Self

Source§

fn with_context<C: Into<OperationContext>>(self, ctx: C) -> Self

Implementors§