Simplify error printing
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 8 May 2016 21:22:46 +0000 (00:22 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 8 May 2016 21:22:46 +0000 (00:22 +0300)
src/cargo/lib.rs

index b149c6386eba782d361ca3218cac6a57827df04c..b3c9c9bbe5be3242e5c58e529641a5a054018e4d 100644 (file)
@@ -35,7 +35,7 @@ use docopt::Docopt;
 use core::{Shell, MultiShell, ShellConfig, Verbosity, ColorConfig};
 use core::shell::Verbosity::{Verbose};
 use core::shell::ColorConfig::{Auto};
-use term::color::{BLACK, RED};
+use term::color::{BLACK};
 
 pub use util::{CargoError, CliError, CliResult, human, Config, ChainError};
 
@@ -178,34 +178,23 @@ pub fn shell(verbosity: Verbosity, color_config: ColorConfig) -> MultiShell {
     }
 }
 
-// `output` print variant error strings to either stderr or stdout.
-// For fatal errors, print to stderr;
-// and for others, e.g. docopt version info, print to stdout.
-fn output(err: String, shell: &mut MultiShell, fatal: bool) {
-    let (std_shell, color, message) = if fatal {
-        (shell.err(), RED, Some("error:"))
-    } else {
-        (shell.out(), BLACK, None)
-    };
-    let _ = match message{
-        Some(text) => std_shell.say_status(text, err.to_string(), color, false),
-        None => std_shell.say(err, color)
-    };
-}
-
 pub fn handle_error(err: CliError, shell: &mut MultiShell) {
     debug!("handle_error; err={:?}", err);
 
     let CliError { error, exit_code, unknown } = err;
-    let fatal = exit_code != 0; // exit_code == 0 is non-fatal error
+    // exit_code == 0 is non-fatal error, e.g. docopt version info
+    let fatal = exit_code != 0;
 
     let hide = unknown && shell.get_verbose() != Verbose;
-    if hide {
-        let _ = shell.err().say_status("error:", "An unknown error occurred",
-                                       RED, false);
+
+    let _ignored_result = if hide {
+        shell.error("An unknown error occurred")
+    } else if fatal {
+        shell.error(&error)
     } else {
-        output(error.to_string(), shell, fatal);
-    }
+        shell.say(&error, BLACK)
+    };
+
     if !handle_cause(&error, shell) || hide {
         let _ = shell.err().say("\nTo learn more, run the command again \
                                  with --verbose.".to_string(), BLACK);