diff --git a/Cargo.lock b/Cargo.lock index f271d058..5217b34a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,6 +65,9 @@ name = "anyhow" version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "508b352bb5c066aac251f6daf6b36eccd03e8a88e8081cd44959ea277a3af9a8" +dependencies = [ + "backtrace", +] [[package]] name = "ascii_tree" diff --git a/Cargo.toml b/Cargo.toml index 7ba04cb2..7f25cc9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ rust-version = "1.60.0" maintenance = {status = "actively-developed"} [dependencies] -anyhow = "1.0.51" +anyhow = {version = "1.0.51", features = ["backtrace"]} async-nats = "0.18.0" atelier_core = "0.2" bytes = "1.0" diff --git a/src/main.rs b/src/main.rs index 45440a76..283f21ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,29 +150,32 @@ async fn main() { 0 } Err(e) => { - let trace = e - .chain() - .skip(1) - .map(|e| format!("{}", e)) - .collect::>(); - match output_kind { OutputKind::Json => { let mut map = HashMap::new(); map.insert("success".to_string(), json!(false)); map.insert("error".to_string(), json!(e.to_string())); - if !trace.is_empty() { - map.insert("trace".to_string(), json!(trace)); + + let error_chain = e + .chain() + .skip(1) + .map(|e| format!("{}", e)) + .collect::>(); + + if !error_chain.is_empty() { + map.insert("error_chain".to_string(), json!(error_chain)); + } + + let backtrace = e.backtrace().to_string(); + + if !backtrace.is_empty() && backtrace != "disabled backtrace" { + map.insert("backtrace".to_string(), json!(backtrace)); } eprintln!("\n{}", serde_json::to_string_pretty(&map).unwrap()); } OutputKind::Text => { - eprintln!("\n{}", e); - if !trace.is_empty() { - eprintln!("Error trace:"); - eprintln!("{}", trace.join("\n")); - } + eprintln!("\n{:?}", e); } } 1