| Crates.io | reveal |
| lib.rs | reveal |
| version | 0.1.2 |
| created_at | 2023-05-15 05:50:21.72214+00 |
| updated_at | 2025-10-05 06:56:42.178927+00 |
| description | Add location and message to errors |
| homepage | |
| repository | https://github.com/luoshuqi/reveal |
| max_upload_size | |
| id | 864748 |
| size | 14,542 |
reveal 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.
cargo add reveal
Here's a basic example demonstrating how to use the chain_err macro to add context to errors:
use reveal::{chain_err, map_err};
fn main() {
if let Err(e) = run() {
println!("{}", e);
}
}
#[chain_err]
fn run() -> reveal::Result<()> {
App.load_config()?;
Ok(())
}
struct App;
#[chain_err]
impl App {
#[chain_err]
fn load_config(&self) -> reveal::Result<Vec<u8>> {
Ok(read("non_exists_config.toml")?)
}
}
fn read(path: &str) -> reveal::Result<Vec<u8>> {
map_err!(std::fs::read(path), "read", path)
}
When the above example is run, it produces the following output:
non_exists_config.toml: No such file or directory (os error 2)
#0 src/main.rs:26 demo::read()
#1 src/main.rs:21 demo::App::load_config()
#2 src/main.rs:11 demo::run()