erreport 0.3.0

A Result helper to catch all the Err propagation path for Rust
Documentation
  • Coverage
  • 37.5%
    3 out of 8 items documented1 out of 2 items with examples
  • Size
  • Source code size: 8.06 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.36 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • qdwang/erreport
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • qdwang

erreport

A Result helper to catch all the Err propagation path

Why?

When an Err propagated, we need a method catch all the propagation path.

So we can get this report in release mode with debug=0:

{package0@version0} src/lib.rs:56 -> src/xx.rs:23 -> {package1@version1} src/lib.rs:42 -> src/yy.rs:632 -> src/zz.rs:56  
  -> {package2@version2} src/lib.rs:251 -> InvalidXXX

Pros over Backtrace

  • No RUST_BACKTRACE=1 needed.
  • No debug=1 needed.
  • Packages and their versions are recorded.

How to use

// This will generate a trait called `pub(crate) trait ToReport<T>` to help to convert any `Result<T, E: std::error::Error>` to `Report`.
// You just need to call once for each crate.
erreport::gen_trait_to_report!(); 

fn test() -> Result<(), erreport::Report> {
    any_result_impl_std_error_Error.to_report()?;
    any_result_impl_std_error_Error.to_report()?;
    Ok(())
}

How to access the actual Error?

fn main() {
    if let Err(err) = test() {
        // This method will bypass all the `Report` wrappers and get the first actual `Error` value.
        err.source() 
    }
}