Make JSON error capture include verbose error output as well

pull/219/head
Chip Senkbeil 10 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::Error(x) => {
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::Json => println!(
"{}",
serde_json::to_string(&serde_json::json!({
"type": "error",
"msg": x.to_string(),
"msg": format!("{x:?}"),
}),)
.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::logger().flush();
ExitCode::FAILURE
}
},

Loading…
Cancel
Save