| Crates.io | reveal |
| lib.rs | reveal |
| version | 0.1.1 |
| created_at | 2023-05-15 05:50:21.72214+00 |
| updated_at | 2025-08-30 14:23:54.77717+00 |
| description | Add location and message to errors |
| homepage | |
| repository | https://github.com/luoshuqi/reveal |
| max_upload_size | |
| id | 864748 |
| size | 14,490 |
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 map_err macro to add context to errors:
use reveal::map_err;
fn main() {
if let Err(e) = run() {
println!("{}", e);
}
}
#[map_err]
fn run() -> reveal::Result<()> {
App.load_config()?;
Ok(())
}
struct App;
#[map_err]
impl App {
#[map_err]
fn load_config(&self) -> reveal::Result<Vec<u8>> {
let config = file_get_contents("non_exists_config.toml")?;
Ok(config)
}
}
#[map_err]
fn file_get_contents(path: &str) -> reveal::Result<Vec<u8>> {
fn read(path: &str) -> reveal::Result<Vec<u8>> {
Ok(std::fs::read(path)?)
}
read(path).map_err(|err| err.context(format!("Failed to read file `{}`", path)))
}
When the above example is run, it produces the following output:
Failed to read file `non_exists_config.toml`: No such file or directory (os error 2)
#0 src/main.rs:29 demo::file_get_contents()
#1 src/main.rs:21 demo::App::load_config()
#2 src/main.rs:11 demo::run()