diff --git a/README.md b/README.md index 12aca78..37ee457 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,46 @@ fn example(&self) -> color_eyre::Result<()> { } ``` +# Example + +```should_panic +use color_eyre::{Help, Report}; +use eyre::WrapErr; +use tracing::{info, instrument}; +use tracing_error::ErrorLayer; +use tracing_subscriber::prelude::*; +use tracing_subscriber::{fmt, EnvFilter}; + +#[instrument] +fn main() -> Result<(), Report> { + let fmt_layer = fmt::layer().with_target(false); + let filter_layer = EnvFilter::try_from_default_env() + .or_else(|_| EnvFilter::try_new("info")) + .unwrap(); + + tracing_subscriber::registry() + .with(filter_layer) + .with(fmt_layer) + .with(ErrorLayer::default()) + .init(); + + Ok(read_config()?) +} + +#[instrument] +fn read_file(path: &str) -> Result<(), Report> { + info!("Reading file"); + Ok(std::fs::read_to_string(path).map(drop)?) +} + +#[instrument] +fn read_config() -> Result<(), Report> { + read_file("fake_file") + .wrap_err("Unable to read config") + .suggestion("try using a file that exists next time") +} +``` + ## Minimal Report Format ![minimal report format](./pictures/minimal.png)