Log error from main using tracing

This commit is contained in:
Louis Dureuil 2024-07-29 14:58:39 +02:00
parent abe128476f
commit fa77a949aa
No known key found for this signature in database

View File

@ -72,6 +72,19 @@ fn on_panic(info: &std::panic::PanicInfo) {
#[actix_web::main] #[actix_web::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
try_main().await.inspect_err(|error| {
tracing::error!(%error);
let mut current = error.source();
let mut depth = 0;
while let Some(source) = current {
tracing::info!(%source, depth, "Error caused by");
current = source.source();
depth += 1;
}
})
}
async fn try_main() -> anyhow::Result<()> {
let (opt, config_read_from) = Opt::try_build()?; let (opt, config_read_from) = Opt::try_build()?;
std::panic::set_hook(Box::new(on_panic)); std::panic::set_hook(Box::new(on_panic));