Browse Source

print errors to stderr

master
Schneider 5 years ago
parent
commit
59f1b41179
Signed by: schneider GPG Key ID: 3F50B02A50039F3B
  1. 12
      src/main.rs

12
src/main.rs

@ -76,17 +76,17 @@ fn main() {
};
if let Err(ref e) = app::main(opts) {
use std::io::prelude::*;
let stderr = std::io::stderr();
let mut lock = stderr.lock();
// Write the top-level error message, then chained errors, then backtrace if available
error!("error: {}", e);
writeln!(lock, "error: {}", e).expect("error while writing error");
for e in e.iter().skip(1) {
error!("caused by: {}", e);
writeln!(lock, "caused by: {}", e).expect("error while writing error");
}
if let Some(backtrace) = e.backtrace() {
error!("backtrace: {:?}", backtrace);
writeln!(lock, "backtrace: {:?}", backtrace).expect("error while writing error");
}
// Exit with a nonzero exit code
// TODO: Decide how to allow code to set this to something other than 1
std::process::exit(1);
}
}

Loading…
Cancel
Save