pub struct ContextError<E, C> {
pub error: E,
pub context: C,
}
Expand description
A wrapper error type that attaches contextual information to an error
Fields§
§error: E
The original error
context: C
The context attached to the error
Implementations§
Source§impl<E, C> ContextError<E, C>
impl<E, C> ContextError<E, C>
Sourcepub fn new(error: E, context: C) -> Self
pub fn new(error: E, context: C) -> Self
Create a new context error wrapping the original error
Sourcepub fn into_error(self) -> E
pub fn into_error(self) -> E
Extract the original error, discarding the context
Sourcepub fn map_context<D, F>(self, f: F) -> ContextError<E, D>where
F: FnOnce(C) -> D,
pub fn map_context<D, F>(self, f: F) -> ContextError<E, D>where
F: FnOnce(C) -> D,
Map the context to a new type using the provided function
Trait Implementations§
Source§impl<E: Error + 'static, C: Display + Debug + Send + Sync + 'static> Error for ContextError<E, C>
impl<E: Error + 'static, C: Display + Debug + Send + Sync + 'static> Error for ContextError<E, C>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl<E: ForgeError, C: Display + Debug + Send + Sync + 'static> ForgeError for ContextError<E, C>
impl<E: ForgeError, C: Display + Debug + Send + Sync + 'static> ForgeError for ContextError<E, C>
Source§fn is_retryable(&self) -> bool
fn is_retryable(&self) -> bool
Returns true if the operation can be retried
Source§fn is_fatal(&self) -> bool
fn is_fatal(&self) -> bool
Returns true if the error is fatal and should terminate the program
Source§fn status_code(&self) -> u16
fn status_code(&self) -> u16
Returns an appropriate HTTP status code for the error
Source§fn user_message(&self) -> String
fn user_message(&self) -> String
Returns a user-facing message that can be shown to end users
Source§fn dev_message(&self) -> String
fn dev_message(&self) -> String
Returns a detailed technical message for developers/logs
Auto Trait Implementations§
impl<E, C> Freeze for ContextError<E, C>
impl<E, C> RefUnwindSafe for ContextError<E, C>where
E: RefUnwindSafe,
C: RefUnwindSafe,
impl<E, C> Send for ContextError<E, C>
impl<E, C> Sync for ContextError<E, C>
impl<E, C> Unpin for ContextError<E, C>
impl<E, C> UnwindSafe for ContextError<E, C>where
E: UnwindSafe,
C: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> ForgeErrorRecovery for Twhere
T: ForgeError,
impl<T> ForgeErrorRecovery for Twhere
T: ForgeError,
Source§fn create_retry_policy(&self, max_retries: usize) -> RetryPolicy
fn create_retry_policy(&self, max_retries: usize) -> RetryPolicy
Create a retry policy optimized for this error type
Source§fn retry<F, T, E>(&self, max_retries: usize, operation: F) -> Result<T, E>
fn retry<F, T, E>(&self, max_retries: usize, operation: F) -> Result<T, E>
Execute a fallible operation with retries if this error type is retryable
Source§fn create_circuit_breaker(&self, name: impl Into<String>) -> CircuitBreaker
fn create_circuit_breaker(&self, name: impl Into<String>) -> CircuitBreaker
Create a circuit breaker for operations that might result in this error type