track-error 0.1.0

This library provides serveral convenient macros to track the location of error where it first happened.
Documentation
  • Coverage
  • 7.14%
    1 out of 14 items documented1 out of 10 items with examples
  • Size
  • Source code size: 9.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.58 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • miaomiao1992

track-error

This library provides a convenient macro and function to track the location of error where it first happened.

Requirements

  • Rust 2021

Usage

Add track-error as a dependency

[dependencies]
track-error = "0.1"

Since this crate just provides a easy and friendly wrapper for the error.

For example:

use track_error::{Track, Tracked, track_error};

fn error_func() -> Result<(), String> {
    Err("something went wrong".to_string())
}

fn track_result() -> Result<(), Tracked<String>> {
    error_func().track()?;
    Ok(())
}

fn track_macro() -> Result<(), Tracked<String>> {
    let _ = error_func().map_err(|e| track_error!(e))?;
    Ok(())
}


fn main() {
    if let Err(e) = track_result() {
        println!("Error: {}", e);
        println!("Location: {}:{}", e.location().0, e.location().1);
    }
  
     if let Err(e) = track_macro() {
        println!("Error: {}", e);
        println!("Location: {}:{}", e.location().0, e.location().1);
    }
}