1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-04 20:32:27 +01:00

Write error messages to pager, if attached

closes #946
This commit is contained in:
sharkdp
2020-04-25 12:25:25 +02:00
committed by David Peter
parent 3bcc4d0d55
commit 48a7ce3bf2
4 changed files with 37 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
use error_chain::error_chain;
use std::io::Write;
error_chain! {
foreign_links {
@@ -11,7 +12,7 @@ error_chain! {
}
}
pub fn default_error_handler(error: &Error) {
pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
use ansi_term::Colour::Red;
match error {
@@ -21,14 +22,16 @@ pub fn default_error_handler(error: &Error) {
::std::process::exit(0);
}
Error(ErrorKind::SerdeYamlError(_), _) => {
eprintln!(
writeln!(
output,
"{}: Error while parsing metadata.yaml file: {}",
Red.paint("[bat error]"),
error
);
)
.ok();
}
_ => {
eprintln!("{}: {}", Red.paint("[bat error]"), error);
writeln!(output, "{}: {}", Red.paint("[bat error]"), error).ok();
}
};
}