Skip to content

Commit

Permalink
Merge pull request bytecodealliance#345 from fastly/acf/fix-error-output
Browse files Browse the repository at this point in the history
[lucetc] restore output for the underlying cause of `lucetc::Error`s
  • Loading branch information
acfoltzer authored Oct 29, 2019
2 parents 61c6384 + e1aa4e1 commit 927d21d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lucetc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ pub struct SerializedLucetcError {
impl From<Error> for SerializedLucetcError {
fn from(e: Error) -> Self {
SerializedLucetcError {
error: format!("{}", e),
error: if let Some(cause) = e.as_fail().cause() {
format!("{}: {}", e, cause)
} else {
format!("{}", e)
},
}
}
}
Expand All @@ -34,7 +38,12 @@ fn main() {

if let Err(err) = run(&opts) {
match opts.error_style {
ErrorStyle::Human => eprintln!("Error: {}\n", err),
ErrorStyle::Human => {
eprintln!("Error: {}\n", err);
if let Some(cause) = err.as_fail().cause() {
eprintln!("{}", cause);
}
}
ErrorStyle::Json => {
let errs: Vec<SerializedLucetcError> = vec![err.into()];
let json = serde_json::to_string(&errs).unwrap();
Expand Down

0 comments on commit 927d21d

Please sign in to comment.