diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 48a54ae4..1499495a 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -211,7 +211,7 @@ fn main() { match result { Err(error) => { - handle_error(&error); + default_error_handler(&error); process::exit(1); } Ok(false) => { diff --git a/src/controller.rs b/src/controller.rs index 7e6b1a67..b0458333 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -20,6 +20,10 @@ impl<'b> Controller<'b> { } pub fn run(&self) -> Result { + self.run_with_error_handler(default_error_handler) + } + + pub fn run_with_error_handler(&self, handle_error: impl Fn(&Error)) -> Result { // Do not launch the pager if NONE of the input files exist let mut paging_mode = self.config.paging_mode; if self.config.paging_mode != PagingMode::Never { diff --git a/src/errors.rs b/src/errors.rs index 9636e13a..607661cf 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -9,7 +9,7 @@ error_chain! { } } -pub fn handle_error(error: &Error) { +pub fn default_error_handler(error: &Error) { match error { Error(ErrorKind::Io(ref io_error), _) if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>