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};
}
}
-// `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);