[][src]Trait eyre::EyreHandler

pub trait EyreHandler: Any + Send + Sync {
    pub fn debug(
        &self,
        error: &(dyn StdError + 'static),
        f: &mut Formatter<'_>
    ) -> Result; pub fn display(
        &self,
        error: &(dyn StdError + 'static),
        f: &mut Formatter<'_>
    ) -> Result { ... }
pub fn track_caller(&mut self, location: &'static Location<'static>) { ... } }

Error Report Handler trait for customizing eyre::Report

Required methods

pub fn debug(
    &self,
    error: &(dyn StdError + 'static),
    f: &mut Formatter<'_>
) -> Result
[src]

Define the report format

Used to override the report format of eyre::Report

Example

use backtrace::Backtrace;
use eyre::EyreHandler;
use eyre::Chain;
use std::error::Error;
use indenter::indented;

pub struct Handler {
    backtrace: Backtrace,
}

impl EyreHandler for Handler {
    fn debug(
        &self,
        error: &(dyn Error + 'static),
        f: &mut core::fmt::Formatter<'_>,
    ) -> core::fmt::Result {
        use core::fmt::Write as _;

        if f.alternate() {
            return core::fmt::Debug::fmt(error, f);
        }

        write!(f, "{}", error)?;

        if let Some(cause) = error.source() {
            write!(f, "\n\nCaused by:")?;
            let multiple = cause.source().is_some();

            for (n, error) in Chain::new(cause).enumerate() {
                writeln!(f)?;
                if multiple {
                    write!(indented(f).ind(n), "{}", error)?;
                } else {
                    write!(indented(f), "{}", error)?;
                }
            }
        }

        let backtrace = &self.backtrace;
        write!(f, "\n\nStack backtrace:\n{:?}", backtrace)?;

        Ok(())
    }
}
Loading content...

Provided methods

pub fn display(
    &self,
    error: &(dyn StdError + 'static),
    f: &mut Formatter<'_>
) -> Result
[src]

Override for the Display format

pub fn track_caller(&mut self, location: &'static Location<'static>)[src]

Store the location of the caller who constructed this error report

Loading content...

Implementations

impl dyn EyreHandler[src]

pub fn is<T: EyreHandler>(&self) -> bool[src]

pub fn downcast_ref<T: EyreHandler>(&self) -> Option<&T>[src]

pub fn downcast_mut<T: EyreHandler>(&mut self) -> Option<&mut T>[src]

Implementors

impl EyreHandler for DefaultHandler[src]

Loading content...