Skip to content

Commit

Permalink
Use stderr for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekuil committed Jan 31, 2017
1 parent 415fd42 commit 3bd5513
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rm-improved"
version = "0.11.2"
version = "0.11.3"
authors = ["[email protected]"]
description = "rip: a safe and ergonomic alternative to rm"
repository = "https://github.com/nivekuil/rip"
Expand Down
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3bd5513

Please sign in to comment.