pub struct StructuredError {
pub code: String,
pub message: String,
pub category: ErrorCategory,
pub severity: ErrorSeverity,
pub retry_hint: RetryHint,
pub source_step_id: Option<String>,
pub attributes: HashMap<String, String>,
pub cause: Option<Box<StructuredError>>,
}Expand description
Structured error with metadata for intelligent error handling.
This extends the basic error information with:
- Category: transient vs permanent (business errors are a subset of permanent)
- Severity: info/warning/error/critical for alerting
- Retry hint: whether and how to retry
- Attributes: additional context key-value pairs
- Cause: nested error for error chains
Fields§
§code: StringMachine-readable error code (e.g., “RATE_LIMITED”, “VALIDATION_ERROR”)
message: StringHuman-readable error message
category: ErrorCategoryError category for routing/retry decisions
severity: ErrorSeverityError severity for logging/alerting
retry_hint: RetryHintHint for retry behavior
source_step_id: Option<String>Which step produced this error (if applicable)
attributes: HashMap<String, String>Additional context as key-value pairs
cause: Option<Box<StructuredError>>Nested cause error (for error chains)
Implementations§
Source§impl StructuredError
impl StructuredError
Sourcepub fn new(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self
Create a new structured error with minimal info.
Sourcepub fn transient(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn transient(code: impl Into<String>, message: impl Into<String>) -> Self
Create a transient error (retry recommended).
Sourcepub fn permanent(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn permanent(code: impl Into<String>, message: impl Into<String>) -> Self
Create a permanent error (don’t retry).
Use for: validation errors, not found, authorization failures, business rule violations.
For business errors (expected outcomes like “credit limit exceeded”), use
.with_severity(ErrorSeverity::Warning) to distinguish from technical failures.
Sourcepub fn with_attr(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with_attr(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add an attribute.
Sourcepub fn with_cause(self, cause: StructuredError) -> Self
pub fn with_cause(self, cause: StructuredError) -> Self
Set a cause error.
Sourcepub fn with_severity(self, severity: ErrorSeverity) -> Self
pub fn with_severity(self, severity: ErrorSeverity) -> Self
Set the severity.
Sourcepub fn with_retry_hint(self, hint: RetryHint) -> Self
pub fn with_retry_hint(self, hint: RetryHint) -> Self
Set the retry hint.
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Returns true if this is a transient error.
Sourcepub fn is_permanent(&self) -> bool
pub fn is_permanent(&self) -> bool
Returns true if this is a permanent error.
Sourcepub fn should_retry(&self) -> bool
pub fn should_retry(&self) -> bool
Returns true if this error should be retried.
Trait Implementations§
Source§impl Clone for StructuredError
impl Clone for StructuredError
Source§impl Debug for StructuredError
impl Debug for StructuredError
Source§impl<'de> Deserialize<'de> for StructuredError
impl<'de> Deserialize<'de> for StructuredError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for StructuredError
impl Display for StructuredError
Source§impl Error for StructuredError
impl Error for StructuredError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<CoreError> for StructuredError
impl From<CoreError> for StructuredError
Auto Trait Implementations§
impl Freeze for StructuredError
impl RefUnwindSafe for StructuredError
impl Send for StructuredError
impl Sync for StructuredError
impl Unpin for StructuredError
impl UnsafeUnpin for StructuredError
impl UnwindSafe for StructuredError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more