Crates.io | conerror |
lib.rs | conerror |
version | 0.1.10 |
source | src |
created_at | 2023-12-27 13:16:32.397274 |
updated_at | 2024-09-19 12:45:26.172809 |
description | Provides a macro that automatically adds context to errors |
homepage | |
repository | https://github.com/luoshuqi/conerror |
max_upload_size | |
id | 1081656 |
size | 6,876 |
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.
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(())
}
}
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()