mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-10-02 23:36:11 +00:00
Add full example to readme
This commit is contained in:
parent
af67c25f9f
commit
043abca81c
40
README.md
40
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
|
||||||
|
|
||||||

|

|
||||||
|
Loading…
x
Reference in New Issue
Block a user