pub struct CapturedError(pub Arc<Error>);Expand description
An anyhow::Error wrapped in an Arc so it can be cheaply cloned and passed around.
Tuple Fields§
§0: Arc<Error>Implementations§
Source§impl CapturedError
impl CapturedError
Sourcepub fn from_display(t: impl Display) -> Self
pub fn from_display(t: impl Display) -> Self
Create a CapturedError from anything that implements Display.
Sourcepub fn new<E>(error: E) -> Self
pub fn new<E>(error: E) -> Self
Create a CapturedError from anything that implements std::error::Error.
Sourcepub fn msg<M>(t: M) -> Self
pub fn msg<M>(t: M) -> Self
Create a CapturedError from anything that implements Display and Debug.
Sourcepub fn from_boxed(boxed_error: Box<dyn Error + Send + Sync + 'static>) -> Self
pub fn from_boxed(boxed_error: Box<dyn Error + Send + Sync + 'static>) -> Self
Create a CapturedError from a boxed std::error::Error.
Sourcepub fn _strong_count(&self) -> usize
pub fn _strong_count(&self) -> usize
Returns the strong count of the underlying error.
Sourcepub fn into_inner(self) -> Option<Error>
pub fn into_inner(self) -> Option<Error>
Try to unwrap the underlying error if this is the only reference to it.
Methods from Deref<Target = Error>§
Sourcepub fn backtrace(&self) -> &Backtrace
pub fn backtrace(&self) -> &Backtrace
Get the backtrace for this Error.
In order for the backtrace to be meaningful, one of the two environment
variables RUST_LIB_BACKTRACE=1 or RUST_BACKTRACE=1 must be defined
and RUST_LIB_BACKTRACE must not be 0. Backtraces are somewhat
expensive to capture in Rust, so we don’t necessarily want to be
capturing them all over the place all the time.
- If you want panics and errors to both have backtraces, set
RUST_BACKTRACE=1; - If you want only errors to have backtraces, set
RUST_LIB_BACKTRACE=1; - If you want only panics to have backtraces, set
RUST_BACKTRACE=1andRUST_LIB_BACKTRACE=0.
§Stability
Standard library backtraces are only available when using Rust ≥
1.65. On older compilers, this function is only available if the crate’s
“backtrace” feature is enabled, and will use the backtrace crate as
the underlying backtrace implementation. The return type of this
function on old compilers is &(impl Debug + Display).
[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }Sourcepub fn chain(&self) -> Chain<'_>
pub fn chain(&self) -> Chain<'_>
An iterator of the chain of source errors contained by this Error.
This iterator will visit every error in the cause chain of this error object, beginning with the error that this error object was created from.
§Example
use anyhow::Error;
use std::io;
pub fn underlying_io_error_kind(error: &Error) -> Option<io::ErrorKind> {
for cause in error.chain() {
if let Some(io_error) = cause.downcast_ref::<io::Error>() {
return Some(io_error.kind());
}
}
None
}Sourcepub fn root_cause(&self) -> &(dyn Error + 'static)
pub fn root_cause(&self) -> &(dyn Error + 'static)
The lowest level cause of this error — this error’s cause’s cause’s cause etc.
The root cause is the last error in the iterator produced by
chain().
Sourcepub fn is<E>(&self) -> bool
pub fn is<E>(&self) -> bool
Returns true if E is the type held by this error object.
For errors with context, this method returns true if E matches the
type of the context C or the type of the error on which the
context has been attached. For details about the interaction between
context and downcasting, see here.
Sourcepub fn downcast_ref<E>(&self) -> Option<&E>
pub fn downcast_ref<E>(&self) -> Option<&E>
Downcast this error object by reference.
§Example
// If the error was caused by redaction, then return a tombstone instead
// of the content.
match root_cause.downcast_ref::<DataStoreError>() {
Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),
None => Err(error),
}Trait Implementations§
Source§impl Clone for CapturedError
impl Clone for CapturedError
Source§fn clone(&self) -> CapturedError
fn clone(&self) -> CapturedError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more