Write error messages to pager, if attached

closes #946
This commit is contained in:
sharkdp authored and David Peter committed 2020-04-25 13:08:00 +02:00
1 parent 3bcc4d0d55
commit 48a7ce3bf2
4 files changed
+37 -10

No files matched your search

+7 -4
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();
}
};
}