just/src/error_result_ext.rs
Casey Rodarmor fe906a1b6f
Fix regression in error message color printing (#566)
Make the word "error" print in red instead of plain text.
2019-12-12 17:55:55 -08:00

23 lines
515 B
Rust

use crate::common::*;
pub(crate) trait ErrorResultExt<T> {
fn eprint(self, color: Color) -> Result<T, i32>;
}
impl<T, E: Error> ErrorResultExt<T> for Result<T, E> {
fn eprint(self, color: Color) -> Result<T, i32> {
match self {
Ok(ok) => Ok(ok),
Err(error) => {
if color.stderr().active() {
eprintln!("{}: {:#}", color.stderr().error().paint("error"), error);
} else {
eprintln!("error: {}", error);
}
Err(error.code())
}
}
}
}