Trait eyre::EyreHandler

source ·
pub trait EyreHandler: Any + Send + Sync {
    // Required method
    fn debug(
        &self,
        error: &(dyn StdError + 'static),
        f: &mut Formatter<'_>
    ) -> Result;

    // Provided methods
    fn display(
        &self,
        error: &(dyn StdError + 'static),
        f: &mut Formatter<'_>
    ) -> Result { ... }
    fn track_caller(&mut self, location: &'static Location<'static>) { ... }
}
Expand description

Error Report Handler trait for customizing eyre::Report

Required Methods§

source

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

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(())
    }
}

Provided Methods§

source

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

Override for the Display format

source

fn track_caller(&mut self, location: &'static Location<'static>)

Store the location of the caller who constructed this error report

Implementations§

source§

impl dyn EyreHandler

source

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

source

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

source

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

Implementors§