Make JSON error capture include verbose error output as well

pull/219/head
Chip Senkbeil 11 months ago
parent df3d771205
commit bcfe6ff9ce
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -122,18 +122,27 @@ impl Termination for MainResult {
CliError::Exit(code) => ExitCode::from(code), CliError::Exit(code) => ExitCode::from(code),
CliError::Error(x) => { CliError::Error(x) => {
match self.format { match self.format {
// For anyhow, we want to print with debug information, which includes the
// full stack of information that anyhow collects; otherwise, we would only
// include the top-level context.
Format::Shell => eprintln!("{x:?}"), Format::Shell => eprintln!("{x:?}"),
Format::Json => println!( Format::Json => println!(
"{}", "{}",
serde_json::to_string(&serde_json::json!({ serde_json::to_string(&serde_json::json!({
"type": "error", "type": "error",
"msg": x.to_string(), "msg": format!("{x:?}"),
}),) }),)
.expect("Failed to format error to JSON") .expect("Failed to format error to JSON")
), ),
} }
// For anyhow, we want to log with debug information, which includes the full
// stack of information that anyhow collects; otherwise, we would only include
// the top-level context.
::log::error!("{x:?}"); ::log::error!("{x:?}");
::log::logger().flush(); ::log::logger().flush();
ExitCode::FAILURE ExitCode::FAILURE
} }
}, },

Loading…
Cancel
Save