Use stderr for errors

This commit is contained in:
Kevin Liu 2017-01-31 04:17:18 -08:00
parent 415fd4288c
commit 3bd5513b77
2 changed files with 10 additions and 4 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "rm-improved"
version = "0.11.2"
version = "0.11.3"
authors = ["mail@nivekuil.com"]
description = "rip: a safe and ergonomic alternative to rm"
repository = "https://github.com/nivekuil/rip"

View file

@ -41,14 +41,20 @@ struct RecordItem<'a> {
fn main() {
if let Err(ref e) = run() {
println!("Error: {}", e);
use ::std::io::Write;
let stderr = &mut ::std::io::stderr();
let errmsg = "Error writing to stderr";
writeln!(stderr, "error: {}", e).expect(errmsg);
for e in e.iter().skip(1) {
println!("Caused by: {}", e);
writeln!(stderr, "caused by: {}", e).expect(errmsg);
}
// The backtrace is not always generated. Try to run this example
// with `RUST_BACKTRACE=1`.
if let Some(backtrace) = e.backtrace() {
println!("Backtrace: {:?}", backtrace);
writeln!(stderr, "backtrace: {:?}", backtrace).expect(errmsg);
}
::std::process::exit(1);