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>
impl<T: DomainReason> StructError<T>
Source§impl<T: DomainReason> StructError<T>
impl<T: DomainReason> StructError<T>
Source§impl<T: DomainReason> StructError<T>
impl<T: DomainReason> StructError<T>
Sourcepub fn attach_source<S>(self, source: S) -> Selfwhere
S: IntoSourcePayload,
pub fn attach_source<S>(self, source: S) -> Selfwhere
S: IntoSourcePayload,
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.
Sourcepub fn with_source<S>(self, source: S) -> Selfwhere
S: IntoSourcePayload,
pub fn with_source<S>(self, source: S) -> Selfwhere
S: IntoSourcePayload,
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.
pub fn source_ref(&self) -> Option<&(dyn StdError + 'static)>
pub fn root_cause(&self) -> Option<&(dyn StdError + 'static)>
pub fn source_frames(&self) -> &[SourceFrame]
pub fn source_payload(&self) -> Option<SourcePayloadRef<'_>>
pub fn source_payload_kind(&self) -> Option<SourcePayloadKind>
pub fn root_cause_frame(&self) -> Option<&SourceFrame>
Sourcepub fn context_metadata(&self) -> ErrorMetadata
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].
Sourcepub fn context_metadata_at(&self, index: usize) -> Option<&ErrorMetadata>
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.
pub fn source_chain(&self) -> Vec<String>
pub fn into_std(self) -> OwnedStdStructError<T>
pub fn into_boxed_std(self) -> Box<dyn StdError + Send + Sync + 'static>
pub fn into_dyn_std(self) -> OwnedDynStdStructErrorwhere
T: DomainReason,
pub fn as_std(&self) -> StdStructRef<'_, T>
pub fn display_chain(&self) -> String
Source§impl<T: DomainReason> StructError<T>
impl<T: DomainReason> StructError<T>
pub fn builder(reason: T) -> StructErrorBuilder<T>
Sourcepub fn with_position(self, position: impl Into<String>) -> Self
pub fn with_position(self, position: impl Into<String>) -> Self
使用示例 self.with_position(location!());
pub fn with_context<C: Into<OperationContext>>(self, context: C) -> Self
pub fn contexts(&self) -> &[OperationContext]
pub fn with_detail(self, detail: impl Into<String>) -> Self
pub fn err<V>(self) -> Result<V, Self>
pub fn target_main(&self) -> Option<String>
pub fn action_main(&self) -> Option<String>
pub fn locator_main(&self) -> Option<String>
Sourcepub fn target(&self) -> Option<String>
pub fn target(&self) -> Option<String>
Compatibility alias for target_main().
Prefer target_main() in new code when pairing it with target_path().
pub fn path_segments(&self) -> Vec<String>
pub fn target_path(&self) -> Option<String>
Source§impl<T: DomainReason> StructError<T>
impl<T: DomainReason> StructError<T>
Sourcepub fn report(&self) -> DiagnosticReport
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"));pub fn into_report(self) -> DiagnosticReport
pub fn report_redacted(&self, policy: &impl RedactPolicy) -> DiagnosticReport
Sourcepub fn render(&self) -> String
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"));pub fn render_redacted(&self, policy: &impl RedactPolicy) -> String
Source§impl<T: DomainReason + ErrorIdentityProvider> StructError<T>
impl<T: DomainReason + ErrorIdentityProvider> StructError<T>
Sourcepub fn exposure_snapshot(
&self,
exposure_policy: &impl ExposurePolicy,
) -> ErrorProtocolSnapshot
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);pub fn into_exposure_snapshot( self, exposure_policy: &impl ExposurePolicy, ) -> ErrorProtocolSnapshot
Source§impl<T> StructError<T>where
T: DomainReason + ErrorIdentityProvider,
impl<T> StructError<T>where
T: DomainReason + ErrorIdentityProvider,
pub fn snapshot(&self) -> ErrorSnapshot
pub fn into_snapshot(self) -> ErrorSnapshot
pub fn identity_snapshot(&self) -> ErrorIdentity
Trait Implementations§
Source§impl<T: Clone + DomainReason> Clone for StructError<T>
impl<T: Clone + DomainReason> Clone for StructError<T>
Source§fn clone(&self) -> StructError<T>
fn clone(&self) -> StructError<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<R1, R2> ConvStructError<R2> for StructError<R1>
impl<R1, R2> ConvStructError<R2> for StructError<R1>
fn conv(self) -> StructError<R2>
Source§impl<T: Debug + DomainReason> Debug for StructError<T>
impl<T: Debug + DomainReason> Debug for StructError<T>
Source§impl<T: DomainReason> Display for StructError<T>
impl<T: DomainReason> Display for StructError<T>
Source§impl<T> ErrorIdentityProvider for StructError<T>where
T: DomainReason + ErrorIdentityProvider,
impl<T> ErrorIdentityProvider for StructError<T>where
T: DomainReason + ErrorIdentityProvider,
fn stable_code(&self) -> &'static str
fn error_category(&self) -> ErrorCategory
Source§impl<T: DomainReason> ErrorWith for StructError<T>
impl<T: DomainReason> ErrorWith for StructError<T>
Source§fn want<S: Into<String>>(self, desc: S) -> Self
fn want<S: Into<String>>(self, desc: S) -> Self
use doing(…) for action contexts; use at(…) for locator/resource contexts
fn position<S: Into<String>>(self, pos: S) -> Self
fn with_context<C: Into<OperationContext>>(self, ctx: C) -> Self
Source§fn attach_context<C: Into<OperationContext>>(self, ctx: C) -> Selfwhere
Self: Sized,
fn attach_context<C: Into<OperationContext>>(self, ctx: C) -> Selfwhere
Self: Sized,
use with_context(…) for full context frames; use doing(…) / at(…) for semantic context helpers
Source§fn with<C: Into<OperationContext>>(self, ctx: C) -> Selfwhere
Self: Sized,
fn with<C: Into<OperationContext>>(self, ctx: C) -> Selfwhere
Self: Sized,
use with_context(…) for full context frames; use at(…) / doing(…) for semantic context helpers