Skip to main content

TypedError

Struct TypedError 

Source
#[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

Source

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.

Source

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.

Source

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.

Source

pub fn error_data(&self) -> Option<&str>

The payload attached with with_error_data, if any.

Source

pub fn error_type(&self) -> &str

The wire ErrorType recorded for this error.

Source

pub fn inner(&self) -> &(dyn Error + 'static)

The wrapped error.

Trait Implementations§

Source§

impl Debug for TypedError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TypedError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Writes the recorded type name as this layer’s frame; the wrapped error is the next frame in the chain.

Source§

impl Error for TypedError

Source§

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

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more