Pavan Kumar Sunkara 59938211cc Add 'color-eyre/' from commit '4a7b4d6988c6b0da5e04e29c9d6e10595b5dc302'
git-subtree-dir: color-eyre
git-subtree-mainline: 0b24ae558f4779afccb1dfc4640c57d9922ff70e
git-subtree-split: 4a7b4d6988c6b0da5e04e29c9d6e10595b5dc302
2023-10-11 21:23:52 +01:00

44 lines
1.1 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::install()?;
read_config()
}
#[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) -> 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")
}