#[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
impl ErasedError
Sourcepub fn from_error<E: Diagnostic>(err: E) -> Self
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.
Sourcepub fn from_error_ref<E: Diagnostic>(err: &E) -> Self
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).
Sourcepub fn source_chain(&self) -> &[Box<str>]
pub fn source_chain(&self) -> &[Box<str>]
The Display of each transported cause, outermost first.
Sourcepub const fn diagnostics(&self) -> &Diagnostics
pub const fn diagnostics(&self) -> &Diagnostics
The transported diagnostic metadata (error code and help text).
Sourcepub const fn location(&self) -> Option<&ErasedLocation>
pub const fn location(&self) -> Option<&ErasedLocation>
The captured caller-location snapshot, if one was transported.
Sourcepub const fn spantrace(&self) -> Option<&ErasedSpanTrace>
pub const fn spantrace(&self) -> Option<&ErasedSpanTrace>
The captured span trace snapshot, if one was transported.
Sourcepub const fn backtrace(&self) -> Option<&ErasedBacktrace>
pub const fn backtrace(&self) -> Option<&ErasedBacktrace>
The captured backtrace snapshot, if one was transported.
Sourcepub fn write_json<W: Write>(&self, f: &mut W) -> Result<(), Error>
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.
Sourcepub fn write_text<W: Write>(&self, f: &mut W) -> Result<()>
pub fn write_text<W: Write>(&self, f: &mut W) -> Result<()>
Write the error in a text format similar to Report.
Sourcepub fn to_text(&self) -> String
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.
Sourcepub fn format_short(&self) -> String
pub fn format_short(&self) -> String
Format the error as a short string without backtrace or spantrace.
Trait Implementations§
Source§impl Clone for ErasedError
impl Clone for ErasedError
Source§fn clone(&self) -> ErasedError
fn clone(&self) -> ErasedError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ErasedError
impl Debug for ErasedError
Source§impl<'de> Deserialize<'de> for ErasedError
impl<'de> Deserialize<'de> for ErasedError
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 Diagnostic for ErasedError
impl Diagnostic for ErasedError
Source§fn oopsie_error_code(&self) -> Option<ErrorCode>
fn oopsie_error_code(&self) -> Option<ErrorCode>
Source§fn oopsie_help_text(&self) -> Option<HelpText>
fn oopsie_help_text(&self) -> Option<HelpText>
Source§fn oopsie_exit_code(&self) -> Option<NonZeroU8>
fn oopsie_exit_code(&self) -> Option<NonZeroU8>
Source§fn oopsie_backtrace(&self) -> Option<&Backtrace>
fn oopsie_backtrace(&self) -> Option<&Backtrace>
Source§fn oopsie_spantrace(&self) -> Option<&SpanTrace>
fn oopsie_spantrace(&self) -> Option<&SpanTrace>
Source§fn oopsie_location(&self) -> Option<&'static Location<'static>>
fn oopsie_location(&self) -> Option<&'static Location<'static>>
Source§impl Display for ErasedError
impl Display for ErasedError
Source§impl Error for ErasedError
impl Error for ErasedError
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 !Freeze for ErasedError
impl RefUnwindSafe for ErasedError
impl Send for ErasedError
impl Sync for ErasedError
impl Unpin for ErasedError
impl UnsafeUnpin for ErasedError
impl UnwindSafe for ErasedError
Blanket Implementations§
Source§impl<T> AsErrorSource for Twhere
T: Error + 'static,
impl<T> AsErrorSource for Twhere
T: Error + 'static,
Source§fn as_error_source(&self) -> &(dyn Error + 'static)
fn as_error_source(&self) -> &(dyn Error + 'static)
&(dyn Error + 'static).