Struct stacked_errors::Error
source · pub struct Error {
pub stack: ThinVec<(ErrorKind, Option<&'static Location<'static>>)>,
}Expand description
An error struct intended for high level error propogation with programmable backtraces
For lower level error propogation, you should still use ordinary Option
and Result with domain-specific enums, it is only when using OS-level
functions or when multiple domains converge that this is intended to be
used. This has an internal stack for different kinds of arbitrary lower
level errors and Locations. When used with the
StackableErr trait, this enables easy conversion and
software defined backtraces for better async debugging. See the crate docs
for more.
Note that due to trait conflicts and not wanting users to accidentally
wastefully embed stacked_errors::Error in a BoxedErr of another
stacked_errors::Error, stacked_errors::Error itself does not actually
implement std::error::Error. This does not pose a problem in most cases
since it is intended to be the highest level of error that is directly
returned or panicked on. However, if a user needs the end result struct to
implement std::error::Error, they can use the
StackedError wrapper.
Fields§
§stack: ThinVec<(ErrorKind, Option<&'static Location<'static>>)>Using a ThinVec has advantages such as taking as little space as
possible on the stack (since we are commiting to some indirection at
this point), and having the niche optimizations applied to things like
Result<(), Error>.
Implementations§
source§impl Error
impl Error
Note: in most cases you can use Error::from or a call from StackableErr
instead of these functions.
sourcepub fn from_err<E: Error + Send + Sync + 'static>(e: E) -> Self
pub fn from_err<E: Error + Send + Sync + 'static>(e: E) -> Self
Returns an error stack with a BoxedError around e, and location
info.
sourcepub fn from_err_locationless<E: Error + Send + Sync + 'static>(e: E) -> Self
pub fn from_err_locationless<E: Error + Send + Sync + 'static>(e: E) -> Self
Same as Error::from_err but without location.
sourcepub fn from_kind_locationless<K: Into<ErrorKind>>(kind: K) -> Self
pub fn from_kind_locationless<K: Into<ErrorKind>>(kind: K) -> Self
Same as Error::from_kind but without location.
sourcepub fn from_box(e: Box<dyn Error + Send + Sync>) -> Self
pub fn from_box(e: Box<dyn Error + Send + Sync>) -> Self
Returns an error stack with just a BoxedErr.
sourcepub fn from_box_locationless(e: Box<dyn Error + Send + Sync>) -> Self
pub fn from_box_locationless(e: Box<dyn Error + Send + Sync>) -> Self
Same as Error::from_box but without location.
sourcepub fn add_kind<K: Into<ErrorKind>>(self, kind: K) -> Self
pub fn add_kind<K: Into<ErrorKind>>(self, kind: K) -> Self
Adds kind to the error stack alongside location information. Use
StackableErr instead of this if anything expensive in creating the
error is involved, because stack_err uses a closure analogous to
ok_or_else.
sourcepub fn add_kind_locationless<K: Into<ErrorKind>>(self, kind: K) -> Self
pub fn add_kind_locationless<K: Into<ErrorKind>>(self, kind: K) -> Self
Same as Error::add_kind but without location.
sourcepub fn add_location(self) -> Self
pub fn add_location(self) -> Self
Only adds track_caller location to the stack
sourcepub fn chain_errors(self, other: Self) -> Self
pub fn chain_errors(self, other: Self) -> Self
Moves the stack of other onto self
sourcepub fn probably_not_root_cause() -> Self
pub fn probably_not_root_cause() -> Self
Returns a base ProbablyNotRootCauseError error
sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Returns if a TimeoutError is in the error stack
sourcepub fn is_probably_not_root_cause(&self) -> bool
pub fn is_probably_not_root_cause(&self) -> bool
Returns if a ProbablyNotRootCauseError is in the error stack
Trait Implementations§
source§impl From<FromUtf16Error> for Error
impl From<FromUtf16Error> for Error
source§fn from(e: FromUtf16Error) -> Self
fn from(e: FromUtf16Error) -> Self
source§impl From<FromUtf8Error> for Error
impl From<FromUtf8Error> for Error
source§fn from(e: FromUtf8Error) -> Self
fn from(e: FromUtf8Error) -> Self
source§impl From<ParseFloatError> for Error
impl From<ParseFloatError> for Error
source§fn from(e: ParseFloatError) -> Self
fn from(e: ParseFloatError) -> Self
source§impl From<ParseIntError> for Error
impl From<ParseIntError> for Error
source§fn from(e: ParseIntError) -> Self
fn from(e: ParseIntError) -> Self
source§impl From<TryFromIntError> for Error
impl From<TryFromIntError> for Error
source§fn from(e: TryFromIntError) -> Self
fn from(e: TryFromIntError) -> Self
source§impl StackableErr for Error
impl StackableErr for Error
type Output = Result<(), Error>
source§fn stack_err<K: Into<ErrorKind>, F: FnOnce() -> K>(self, f: F) -> Self::Output
fn stack_err<K: Into<ErrorKind>, F: FnOnce() -> K>(self, f: F) -> Self::Output
f and location information to the error stacksource§fn stack_err_locationless<K: Into<ErrorKind>, F: FnOnce() -> K>(
self,
f: F
) -> Self::Output
fn stack_err_locationless<K: Into<ErrorKind>, F: FnOnce() -> K>( self, f: F ) -> Self::Output
f without location information to the error stacksource§fn stack_locationless(self) -> Self::Output
fn stack_locationless(self) -> Self::Output
Self::Output and pushes it on the error stack