Skip to main content

StructError

Struct StructError 

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

Structured runtime error carrier with explicit bridge APIs for the standard error ecosystem.

use orion_error::{StructError, UvsReason};

let err = StructError::from(UvsReason::system_error());
let _ = std::error::Error::source(&err);
use orion_error::{StructError, UvsReason};

let err = StructError::from(UvsReason::system_error());
let bridged = err.as_std();
let _ = std::error::Error::source(&bridged);

Implementations§

Source§

impl<T: DomainReason> StructError<T>

Source

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

Source§

impl<T: DomainReason> StructError<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 attach_source<S>(self, source: S) -> Self

Attach any source that can be converted into the dual-channel source payload model.

Ordinary StdError values attach as SourcePayloadKind::Std, while StructError<_> attaches as SourcePayloadKind::Struct.

Source

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

Auto-route a source error through the dual-channel source model.

This is the recommended public entry point for attaching sources. It accepts both standard StdError values and StructError<_> values, automatically routing through the correct internal channel via the IntoSourcePayload trait.

For call sites that need to explicitly choose the source kind, use attach_source instead.

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

Returns merged metadata from all context layers.

Context layers are iterated in push order (innermost first). The merge uses an inner wins strategy: the first value set for any key is kept; outer layers only supply keys that are missing from inner layers.

For example, if inner context sets key = "inner" and outer context sets key = "outer", the result is key = "inner".

To query metadata from a specific context layer, use [context_metadata_at].

Source

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

Returns the metadata from a specific context layer by index.

Index 0 is the innermost (first pushed) context layer. Returns None if the index is out of bounds.

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

使用示例 self.with_position(location!());

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 target_main(&self) -> Option<String>

Source

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

Source

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

Source

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

Compatibility alias for target_main().

Prefer target_main() in new code when pairing it with target_path().

Source

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

Source

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

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, UvsReason};
use orion_error::report::DiagnosticReport;

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

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

pub fn into_report(self) -> DiagnosticReport

Source

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

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::UvsReason;

let s = StructError::from(UvsReason::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

Source§

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

Source

pub fn exposure_snapshot( &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::{DefaultExposurePolicy, StructError, UvsReason};

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

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

Source§

impl<T> StructError<T>

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 want<S: Into<String>>(self, desc: S) -> Self

👎Deprecated since 0.7.0:

use doing(…) for action contexts; use at(…) for locator/resource contexts

Source§

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

Source§

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

Source§

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

👎Deprecated since 0.7.0:

use with_context(…) for full context frames; use doing(…) / at(…) for semantic context helpers

Source§

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

👎Deprecated since 0.7.0:

use with_context(…) for full context frames; use at(…) / doing(…) for semantic context helpers

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<T> From<&StructError<T>> for ErrorSnapshot

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<&StructError<T>> for StableErrorSnapshot

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<StructError<T>> for ErrorSnapshot

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<StructError<T>> for StableErrorSnapshot

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<R> IntoSourcePayload for StructError<R>
where R: DomainReason,

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.
Source§

impl<R1, R2> WrapStructErrorAs<R2> for StructError<R1>
where R1: DomainReason, R2: DomainReason,

Source§

fn wrap_as(self, reason: R2, detail: impl Into<String>) -> StructError<R2>

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> 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.
Source§

impl<T> UvsFrom for T
where T: From<UvsReason>,

Source§

fn from_conf() -> Self

Source§

fn from_conf_reason(reason: ConfErrReason) -> Self

Source§

fn from_data() -> Self

Source§

fn from_sys() -> Self

Source§

fn from_biz() -> Self

Source§

fn from_logic() -> Self

Source§

fn from_rule() -> Self

Source§

fn from_res() -> Self

Source§

fn from_net() -> Self

Source§

fn from_timeout() -> Self

Source§

fn from_validation() -> Self

Source§

fn from_not_found() -> Self

Source§

fn from_permission() -> Self

Source§

fn from_external() -> Self