#[non_exhaustive]pub struct TypedError { /* private fields */ }Expand description
An error wrapper that records its inner error’s concrete type name for
the wire ErrorType.
Rust erases an error’s concrete type the moment it is boxed into a
BoxError: inside the SDK there is no runtime name
to recover, so an unwrapped error is recorded with the generic type
"Error". Wrapping the error at the one place its type is still known
(its creation site) is the explicit alternative:
use aws_durable_execution_sdk::{BoxError, TypedError};
#[derive(Debug)]
struct PaymentDeclined;
let err: BoxError = Box::new(TypedError::new(PaymentDeclined));
// The step that fails with `err` records ErrorType "PaymentDeclined".with_error_data attaches an opaque payload,
recorded as the wire ErrorData. The SDK never parses it, and it
never appears in the recorded message:
use aws_durable_execution_sdk::TypedError;
let err = TypedError::with_type("PaymentError", "declined").with_error_data(r#"{"code":42}"#);
assert_eq!(err.error_type(), "PaymentError");
assert_eq!(err.error_data(), Some(r#"{"code":42}"#));The wrapper is one chain layer: its Display frame is the recorded
type name, and its source() is the
wrapped error itself, so the concrete error stays reachable through
the ordinary source() downcast walk, and the alternate form {:#}
reads "TransientError: temporary failure".
The recorded message never includes the type name, because the record
carries it as its type, as JS records an error’s name and message
apart. A failure with TypedError::with_type("PaymentError", "declined")
records the type PaymentError and the message declined. When the
wrapped error propagates another operation’s failure, the message is
that failure’s recorded message.
Implementations§
Source§impl TypedError
impl TypedError
Sourcepub fn new<E: Error + Send + Sync + 'static>(err: E) -> Self
pub fn new<E: Error + Send + Sync + 'static>(err: E) -> Self
Wraps err, recording its concrete type’s name (without module
path) as the wire ErrorType.
Sourcepub fn with_type(
error_type: impl Into<String>,
err: impl Into<Box<dyn Error + Send + Sync + 'static>>,
) -> Self
pub fn with_type( error_type: impl Into<String>, err: impl Into<Box<dyn Error + Send + Sync + 'static>>, ) -> Self
Wraps err under an explicitly chosen wire ErrorType.
Sourcepub fn with_error_data(self, error_data: impl Into<String>) -> Self
pub fn with_error_data(self, error_data: impl Into<String>) -> Self
Attaches an opaque payload, recorded as the wire ErrorData.
The SDK passes the payload through unparsed. It does not appear in
this error’s Display or in the recorded ErrorMessage.
Sourcepub fn error_data(&self) -> Option<&str>
pub fn error_data(&self) -> Option<&str>
The payload attached with with_error_data,
if any.
Sourcepub fn error_type(&self) -> &str
pub fn error_type(&self) -> &str
The wire ErrorType recorded for this error.
Trait Implementations§
Source§impl Debug for TypedError
impl Debug for TypedError
Source§impl Display for TypedError
impl Display for TypedError
Source§impl Error for TypedError
impl Error for TypedError
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()
Auto Trait Implementations§
impl !RefUnwindSafe for TypedError
impl !UnwindSafe for TypedError
impl Forget for TypedError
impl Freeze for TypedError
impl Move for TypedError
impl Send for TypedError
impl Sync for TypedError
impl Unpin for TypedError
impl UnsafeUnpin for TypedError
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> 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