eyre/examples/panic_hook.rs
Stu 5cf35afaa8
Add panic_note to HookBuilder (#51)
* Implement panic_note feature

* Fix typo

* Rename to panic_section and use Display impl

* Update src/config.rs

* Move panic_section after panic message

Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2020-08-24 13:09:33 -07:00

47 lines
1.0 KiB
Rust

use color_eyre::{eyre::Report, eyre::WrapErr, Section};
use tracing::{info, instrument};
#[instrument]
fn main() -> Result<(), Report> {
#[cfg(feature = "capture-spantrace")]
install_tracing();
color_eyre::config::HookBuilder::default()
.panic_section("consider reporting the bug on github")
.install()?;
read_config();
Ok(())
}
#[cfg(feature = "capture-spantrace")]
fn install_tracing() {
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};
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();
}
#[instrument]
fn read_file(path: &str) {
if let Err(e) = std::fs::read_to_string(path) {
panic!("{}", e);
}
}
#[instrument]
fn read_config() {
read_file("fake_file")
}