track-error 0.1.0

This library provides serveral convenient macros to track the location of error where it first happened.
Documentation
use thiserror::Error;
use track_error::track_error;
use track_error::Track as _;
use track_error::Tracked;

#[derive(Error, Debug)]
pub enum DemoError {
    #[error("Tracked! {0}")]
    None(#[from] Tracked<NoneError>),

    #[error("Tracked! {0}")]
    Custom(#[from] Tracked<CustomError>),

    #[error("unknown error")]
    Unknown,
}

#[derive(Error, Debug)]
#[error("NoneError")]
pub struct NoneError;

#[derive(Error, Debug)]
#[error("CustomError")]
pub struct CustomError;

fn main() {
    let _ = handler().inspect_err(|e| println!("{}", e));
    let _ = handler2().inspect_err(|e| println!("{}", e));
    let _ = handler3().inspect_err(|e| println!("{}", e));
}

fn handler() -> Result<(), DemoError> {
    service()
}

fn service() -> Result<(), DemoError> {
    repository()
}

fn repository() -> Result<(), DemoError> {
    let input: Option<String> = None;
    let _ = input.ok_or(NoneError).map_err(|e| track_error!(e))?;

    Ok(())
}

fn handler2() -> Result<(), DemoError> {
    service2()
}

fn service2() -> Result<(), DemoError> {
    repository2()
}

fn repository2() -> Result<(), DemoError> {
    let input: Option<String> = None;
    let _ = input.ok_or(NoneError).track()?;

    Ok(())
}

fn handler3() -> Result<(), DemoError> {
    service3()
}

fn service3() -> Result<(), DemoError> {
    repository3()
}

fn repository3() -> Result<(), DemoError> {
    let input: Option<String> = None;
    let _ = input.ok_or(CustomError).track()?;

    Ok(())
}