[−][src]Struct color_eyre::Context
A custom context type for eyre::Report
which provides colorful error
reports and tracing-error
support.
This type is not intended to be used directly, prefer using it via the
color_eyre::Report
and color_eyre::Result
type aliases.
Implementations
impl Context
[src]
pub fn backtrace(&self) -> Option<&Backtrace>
[src]
Return a reference to the captured Backtrace
type
Examples
Backtrace capture can be enabled with the RUST_BACKTRACE
env variable:
use color_eyre::Report; use eyre::eyre; std::env::set_var("RUST_BACKTRACE", "1"); let report: Report = eyre!("an error occurred"); assert!(report.context().backtrace().is_some());
Alternatively, if you don't want backtraces to be printed on panic, you can use
RUST_LIB_BACKTRACE
:
use color_eyre::Report; use eyre::eyre; std::env::set_var("RUST_LIB_BACKTRACE", "1"); let report: Report = eyre!("an error occurred"); assert!(report.context().backtrace().is_some());
And if you don't want backtraces to be captured but you still want panics to print
backtraces you can explicitly set RUST_LIB_BACKTRACE
to 0:
use color_eyre::Report; use eyre::eyre; std::env::set_var("RUST_BACKTRACE", "1"); std::env::set_var("RUST_LIB_BACKTRACE", "0"); let report: Report = eyre!("an error occurred"); assert!(report.context().backtrace().is_none());
pub fn span_trace(&self) -> Option<&SpanTrace>
[src]
feature="capture-spantrace"
only.Return a reference to the captured SpanTrace
type
Examples
SpanTraces are always captured by default:
use color_eyre::Report; use eyre::eyre; let report: Report = eyre!("an error occurred"); assert!(report.context().span_trace().is_some());
However, SpanTrace
is not captured if one of the source errors already captured a
SpanTrace
via tracing_error::TracedError
:
use color_eyre::Report; use eyre::eyre; use tracing_error::{TracedError, InstrumentError}; #[derive(Debug)] struct SourceError; impl std::fmt::Display for SourceError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "SourceError") } } impl std::error::Error for SourceError {} let error = SourceError; // the type annotation here is unnecessary, I've only added it for demonstration purposes let error: TracedError<SourceError> = error.in_current_span(); let report: Report = error.into(); assert!(report.context().span_trace().is_none());
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,