| Crates.io | track-error |
| lib.rs | track-error |
| version | 0.1.0 |
| created_at | 2025-08-22 11:45:45.548474+00 |
| updated_at | 2025-08-22 11:45:45.548474+00 |
| description | This library provides serveral convenient macros to track the location of error where it first happened. |
| homepage | |
| repository | https://github.com/miaomiao1992/track-error |
| max_upload_size | |
| id | 1806224 |
| size | 9,561 |
This library provides a convenient macro and function to track the location of error where it first happened.
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);
}
}