ts-error-stack 0.1.0

Simple error stacks for better reporting
Documentation
//! Example showing the output of the report.

use core::{error::Error, fmt};
use std::io;

use ts_error_stack::Report;

fn main() -> Result<(), Report<MainError>> {
    Err(MainError::ReadConfigFile {
        source: ReadConfigFileError(io::Error::new(
            io::ErrorKind::NotFound,
            "the file `some-fake-file` could not be found",
        )),
    }
    .into())
}

/// The error variants returned from the main function
#[derive(Debug)]
enum MainError {
    /// The config file could not be read
    ReadConfigFile {
        /// The source of this error.
        source: ReadConfigFileError,
    },
}
impl fmt::Display for MainError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "main_exit encountered an error")
    }
}
impl Error for MainError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        match &self {
            Self::ReadConfigFile { source, .. } => Some(source),
        }
    }
}

/// The config file could not be read
#[derive(Debug)]
struct ReadConfigFileError(io::Error);
impl fmt::Display for ReadConfigFileError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "the config file could not be read")
    }
}
impl Error for ReadConfigFileError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        Some(&self.0)
    }
}