Skip to main content

StructError

Struct StructError 

Source
pub struct StructError<T: DomainReason> { /* private fields */ }

Implementations§

Source§

impl<T: DomainReason> StructError<T>

Source

pub fn imp(&self) -> &StructErrorImpl<T>

Source

pub fn reason(&self) -> &T

Source

pub fn detail(&self) -> &Option<String>

Source

pub fn position(&self) -> &Option<String>

Source

pub fn new( reason: T, detail: Option<String>, position: Option<String>, context: Vec<OperationContext>, ) -> Self

Source§

impl<T: DomainReason> StructError<T>

Source

pub fn with_std_source<E>(self, source: E) -> Self
where E: StdError + Send + Sync + 'static,

Source

pub fn with_source<S>(self, source: S) -> Self
where S: IntoSourcePayload,

Source

pub fn with_struct_source<R>(self, source: StructError<R>) -> Self
where R: DomainReason,

Source

pub fn source_ref(&self) -> Option<&(dyn StdError + 'static)>

Source

pub fn root_cause(&self) -> Option<&(dyn StdError + 'static)>

Source

pub fn source_frames(&self) -> &[SourceFrame]

Source

pub fn source_payload(&self) -> Option<SourcePayloadRef<'_>>

Source

pub fn source_payload_kind(&self) -> Option<SourcePayloadKind>

Source

pub fn root_cause_frame(&self) -> Option<&SourceFrame>

Source

pub fn context_metadata(&self) -> ErrorMetadata

Source

pub fn context_metadata_at(&self, index: usize) -> Option<&ErrorMetadata>

Source

pub fn source_chain(&self) -> Vec<String>

Source

pub fn into_std(self) -> OwnedStdStructError<T>

Source

pub fn into_boxed_std(self) -> Box<dyn StdError + Send + Sync + 'static>

Source

pub fn into_dyn_std(self) -> OwnedDynStdStructError
where T: DomainReason,

Source

pub fn as_std(&self) -> StdStructRef<'_, T>

Source

pub fn display_chain(&self) -> String
where T: Debug + Display + 'static,

Source§

impl<T: DomainReason> StructError<T>

Source

pub fn builder(reason: T) -> StructErrorBuilder<T>

Source

pub fn with_position(self, position: impl Into<String>) -> Self

Source

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

Source

pub fn contexts(&self) -> &[OperationContext]

Source

pub fn with_detail(self, detail: impl Into<String>) -> Self

Source

pub fn err<V>(self) -> Result<V, Self>

Source

pub fn action_main(&self) -> Option<String>

Source

pub fn locator_main(&self) -> Option<String>

Source

pub fn path_segments(&self) -> Vec<String>

Source

pub fn target_path(&self) -> Option<String>

Source§

impl<T> StructError<T>

Source

pub fn identity_snapshot(&self) -> ErrorIdentity

Build an ErrorIdentity from this error.

Source§

impl<T: DomainReason> StructError<T>

Source

pub fn report(&self) -> DiagnosticReport

Build a DiagnosticReport from this error.

The report carries human-readable reason, detail, context, and source frames — no identity or protocol data.

§Example
use orion_error::{StructError, UnifiedReason};
use orion_error::report::DiagnosticReport;

let err = StructError::from(UnifiedReason::validation_error())
    .with_detail("field `email` is required");

let report: DiagnosticReport = err.report();
assert!(report.reason().contains("validation"));
assert_eq!(report.detail(), Some("field `email` is required"));
Source

pub fn into_report(self) -> DiagnosticReport

Consume this error and return its human-readable diagnostic report.

§Example
use orion_error::{StructError, UnifiedReason};

let report = StructError::from(UnifiedReason::validation_error())
    .with_detail("field `email` is required")
    .into_report();

assert!(report.reason().contains("validation"));
assert_eq!(report.detail(), Some("field `email` is required"));
Source

pub fn report_redacted(&self, policy: &impl RedactPolicy) -> DiagnosticReport

Build a redacted DiagnosticReport using the provided policy.

§Example
use orion_error::{StructError, UnifiedReason};
use orion_error::report::RedactPolicy;

struct HideDetail;

impl RedactPolicy for HideDetail {
    fn redact_value(&self, key: Option<&str>, value: &str) -> Option<String> {
        if key == Some("detail") {
            Some("<redacted>".to_string())
        } else {
            Some(value.to_string())
        }
    }
}

let report = StructError::from(UnifiedReason::validation_error())
    .with_detail("token=abc")
    .report_redacted(&HideDetail);

assert_eq!(report.detail(), Some("<redacted>"));
Source

pub fn render(&self) -> String

Render this error as a human-readable diagnostic string.

Delegates to DiagnosticReport::render().

§Example
use orion_error::StructError;
use orion_error::reason::UnifiedReason;

let s = StructError::from(UnifiedReason::validation_error())
    .with_detail("field `email` is required")
    .render();
assert!(s.contains("validation"));
assert!(s.contains("field `email` is required"));
Source

pub fn render_redacted(&self, policy: &impl RedactPolicy) -> String

Render a redacted human-readable diagnostic string.

§Example
use orion_error::{StructError, UnifiedReason};
use orion_error::report::RedactPolicy;

struct HideDetail;

impl RedactPolicy for HideDetail {
    fn redact_value(&self, key: Option<&str>, value: &str) -> Option<String> {
        if key == Some("detail") {
            Some("<redacted>".to_string())
        } else {
            Some(value.to_string())
        }
    }
}

let rendered = StructError::from(UnifiedReason::validation_error())
    .with_detail("token=abc")
    .render_redacted(&HideDetail);

assert!(rendered.contains("detail: <redacted>"));
Source§

impl<T: DomainReason + ErrorIdentityProvider> StructError<T>

Source

pub fn exposure( &self, exposure_policy: &impl ExposurePolicy, ) -> ErrorProtocolSnapshot

Build an ErrorProtocolSnapshot by combining identity, exposure decision, and diagnostic report in one pass.

This is the primary entry point for protocol-level error output. Requires ErrorIdentityProvider (provided by #[derive(OrionError)]).

§Example
use orion_error::protocol::DefaultExposurePolicy;
use orion_error::{StructError, UnifiedReason};

let err = StructError::from(UnifiedReason::system_error())
    .with_detail("disk full");
let proto = err.exposure(&DefaultExposurePolicy);
assert_eq!(proto.identity.code, "sys.io_error");
assert_eq!(proto.decision.http_status, 500);
Source

pub fn into_exposure( self, exposure_policy: &impl ExposurePolicy, ) -> ErrorProtocolSnapshot

Consume this error and return its protocol/exposure snapshot.

§Example
use orion_error::protocol::DefaultExposurePolicy;
use orion_error::{StructError, UnifiedReason};

let proto = StructError::from(UnifiedReason::system_error())
    .with_detail("disk full")
    .into_exposure(&DefaultExposurePolicy);

assert_eq!(proto.identity.code, "sys.io_error");
assert_eq!(proto.decision.http_status, 500);

Trait Implementations§

Source§

impl<T: Clone + DomainReason> Clone for StructError<T>

Source§

fn clone(&self) -> StructError<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R1, R2> ConvStructError<R2> for StructError<R1>
where R1: DomainReason, R2: DomainReason + From<R1>,

Source§

fn conv(self) -> StructError<R2>

Source§

impl<T: Debug + DomainReason> Debug for StructError<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: DomainReason> Display for StructError<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> ErrorIdentityProvider for StructError<T>

Source§

impl<T: DomainReason> ErrorWith for StructError<T>

Source§

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

Source§

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

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,

Source§

impl<'a, R> From<&'a StructError<R>> for StdStructRef<'a, R>
where R: DomainReason,

Source§

fn from(value: &'a StructError<R>) -> Self

Converts to this type from the input type.
Source§

impl<T: DomainReason> From<&StructError<T>> for DiagnosticReport

Source§

fn from(value: &StructError<T>) -> Self

Converts to this type from the input type.
Source§

impl<R> From<StructError<R>> for OwnedDynStdStructError
where R: DomainReason,

Source§

fn from(value: StructError<R>) -> Self

Converts to this type from the input type.
Source§

impl<R> From<StructError<R>> for OwnedStdStructError<R>
where R: DomainReason,

Source§

fn from(value: StructError<R>) -> Self

Converts to this type from the input type.
Source§

impl<T: DomainReason> From<StructError<T>> for DiagnosticReport

Source§

fn from(value: StructError<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for StructError<T>
where T: DomainReason,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: DomainReason> PartialEq for StructError<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for StructError<T>

§

impl<T> !RefUnwindSafe for StructError<T>

§

impl<T> Send for StructError<T>

§

impl<T> Sync for StructError<T>

§

impl<T> Unpin for StructError<T>

§

impl<T> UnsafeUnpin for StructError<T>

§

impl<T> !UnwindSafe for StructError<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.