8 releases

0.1.7 Sep 19, 2024
0.1.6 Jul 1, 2024
0.1.5 Mar 27, 2024
0.1.3 Feb 27, 2024
0.1.0 Dec 27, 2023

#2250 in Procedural macros

Download history 142/week @ 2024-06-27 17/week @ 2024-07-04 2/week @ 2024-07-18 23/week @ 2024-07-25 4/week @ 2024-08-29 112/week @ 2024-09-19 10/week @ 2024-09-26 4/week @ 2024-10-03 4/week @ 2024-10-10

130 downloads per month
Used in conerror

MIT license

5KB
81 lines

Conerror

conerror is a Rust library designed to automatically add context to errors, making it easier to trace and debug issues by including file names, line numbers, and function names in error messages.

Features

  • Automatically adds context to errors.
  • Works with any error type that implements std::error::Error.
  • Provides detailed error tracebacks.

Examples

Here's a basic example demonstrating how to use the conerror macro to add context to errors:

use conerror::conerror;
use std::fs::read;

fn main() {
    if let Err(e) = func1() {
        println!("{}", e);
    }
}

#[conerror]
fn func1() -> conerror::Result<()> {
    func2()?;
    Ok(())
}

#[conerror]
fn func2() -> conerror::Result<()> {
    Read.read()?;
    Ok(())
}

struct Read;

#[conerror]
impl Read {
    #[conerror]
    fn read(&self) -> conerror::Result<()> {
        read("/root")?;
        Ok(())
    }
}

Output:

When the above example is run, it produces the following output:

Permission denied (os error 13)
#0 src/main.rs:28 untitled::Read::read()
#1 src/main.rs:18 untitled::func2()
#2 src/main.rs:12 untitled::func1()

Dependencies

~240–680KB
~16K SLoC