Skip to main content

ErasedError

Struct ErasedError 

Source
#[non_exhaustive]
pub struct ErasedError { /* private fields */ }
Expand description

A serializable, cloneable error representation that preserves the full error context including backtrace, spantrace, and source chain.

This type is designed for API error responses where the original error cannot be directly serialized. Construct one with from_error or from_error_ref, or by deserializing a transported payload; read its contents through the accessor methods.

The captured backtrace, span trace, and caller location are exposed via backtrace, spantrace, and location as ErasedBacktrace / ErasedSpanTrace / ErasedLocation snapshots. They are not surfaced through the Diagnostic impl: those accessors return references to live Backtrace/SpanTrace values and a &'static Location, which a transported snapshot cannot reconstruct. Re-erasing an ErasedError (via from_error_ref) preserves the message, source chain, code, help, and exit code, but the trace and location snapshots stay reachable only through this type’s own accessors.

Implementations§

Source§

impl ErasedError

Source

pub fn from_error<E: Diagnostic>(err: E) -> Self

Create an ErasedError from any error implementing Diagnostic.

This extracts the message, source chain, backtrace, spantrace, error code, and help text via the Diagnostic trait.

Source

pub fn from_error_ref<E: Diagnostic>(err: &E) -> Self

Create an ErasedError from a reference to any error implementing Diagnostic.

Like from_error but takes a reference, useful when ownership cannot be transferred (e.g., in Serialize implementations).

Source

pub fn message(&self) -> &str

The primary error message (the original error’s Display).

Source

pub fn source_chain(&self) -> &[Box<str>]

The Display of each transported cause, outermost first.

Source

pub const fn diagnostics(&self) -> &Diagnostics

The transported diagnostic metadata (error code and help text).

Source

pub const fn location(&self) -> Option<&ErasedLocation>

The captured caller-location snapshot, if one was transported.

Source

pub const fn spantrace(&self) -> Option<&ErasedSpanTrace>

The captured span trace snapshot, if one was transported.

Source

pub const fn backtrace(&self) -> Option<&ErasedBacktrace>

The captured backtrace snapshot, if one was transported.

Source

pub fn write_json<W: Write>(&self, f: &mut W) -> Result<(), Error>

Serialize the error as pretty-printed JSON to a writer.

§Errors

Returns the serialization error, including any underlying I/O failure from the writer.

Source

pub fn write_text<W: Write>(&self, f: &mut W) -> Result<()>

Write the error in a text format similar to Report.

Source

pub fn to_text(&self) -> String

The full multi-line text report (header, source chain, help, traces) as a String. Display intentionally prints only the message so an ErasedError embeds cleanly in another error’s source chain.

Source

pub fn format_short(&self) -> String

Format the error as a short string without backtrace or spantrace.

Trait Implementations§

Source§

impl Clone for ErasedError

Source§

fn clone(&self) -> ErasedError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ErasedError

Source§

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

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

impl<'de> Deserialize<'de> for ErasedError

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Diagnostic for ErasedError

Source§

fn oopsie_error_code(&self) -> Option<ErrorCode>

Returns the error code associated with this error.
Source§

fn oopsie_help_text(&self) -> Option<HelpText>

Returns the help text associated with this error.
Source§

fn oopsie_exit_code(&self) -> Option<NonZeroU8>

Returns the process exit code this error should terminate with. Read more
Source§

fn oopsie_backtrace(&self) -> Option<&Backtrace>

Returns the backtrace captured when this error was created.
Source§

fn oopsie_spantrace(&self) -> Option<&SpanTrace>

Returns the span trace captured when this error was created.
Source§

fn oopsie_location(&self) -> Option<&'static Location<'static>>

Returns the caller location captured when this error was created.
Source§

impl Display for ErasedError

Source§

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

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

impl Error for ErasedError

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

impl Serialize for ErasedError

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> AsErrorSource for T
where T: Error + 'static,

Source§

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

Borrow this value as a &(dyn Error + 'static).
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<E> ErrorChainExt for E
where E: Error + 'static,

Source§

fn chain(&self) -> Chain<'_>

Iterate this error followed by its transitive source causes. Read more
Source§

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

The last error in the chain: the deepest source, or this error itself when it has none.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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<E> InstrumentError for E
where TracedError<E>: From<E>,

Source§

type Instrumented = TracedError<E>

The type of the wrapped error after instrumentation
Source§

fn in_current_span(self) -> <E as InstrumentError>::Instrumented

Instrument an Error by bundling it with a SpanTrace 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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