From 23f66a1cc460307e99d9d9d9fd85ed95ad7af8c7 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 25 Feb 2018 10:15:19 -0500 Subject: [PATCH 1/2] Replace writeln! error calls with eprintln! --- src/main.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 71b4793..7e1edf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,6 @@ use clap::{App, Arg, ArgMatches, SubCommand}; use rustdoc::{build, error, Config, Result, Verbosity}; -use std::io::{stderr, Write}; use std::process; use std::path::PathBuf; @@ -310,16 +309,13 @@ fn check_unimplemented_flags(matches: &ArgMatches) { fn main() { if let Err(e) = run() { - let stderr = &mut stderr(); - let errmsg = "Error writing to stderr"; + eprintln!("Error: {}", e); - writeln!(stderr, "Error: {}", e).expect(errmsg); - - writeln!(stderr, "Caused by: {}", e.cause()).expect(errmsg); + eprintln!("Caused by: {}", e.cause()); // The backtrace is not always generated. Try to run this example // with `RUST_BACKTRACE=1`. - writeln!(stderr, "Backtrace, if any: {:?}", e.backtrace()).expect(errmsg); + eprintln!("Backtrace, if any: {:?}", e.backtrace()); process::exit(1); } From ffd4cfa68dd76d2071d65061ab159b7ca3cc344a Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 25 Feb 2018 10:20:56 -0500 Subject: [PATCH 2/2] Don't print backtrace line unless we have a backtrace. --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7e1edf4..638385d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,7 +315,10 @@ fn main() { // The backtrace is not always generated. Try to run this example // with `RUST_BACKTRACE=1`. - eprintln!("Backtrace, if any: {:?}", e.backtrace()); + let backtrace = e.backtrace().to_string(); + if !backtrace.is_empty() { + eprintln!("Backtrace: {:?}", backtrace); + } process::exit(1); }