on master help sign in
Move error handling to a callback
commitfc1ca0875a569f9fd956ae2b424c0ed235f28d27 authorsharkdp <davidpeter@web.de> dateSat 21 Mar 2020, 19:51 (7 years ago) parenta7338e2
3 files changed+6−2
src/bin/bat/main.rs+1−1 src/controller.rs+4 src/errors.rs+1−1
src/bin/bat/main.rs+1−1
@@ -211,7 +211,7 @@ fn main() {
211211
212212 match result {
213213 Err(error) => {
214− handle_error(&error);
214+ default_error_handler(&error);
215215 process::exit(1);
216216 }
217217 Ok(false) => {
src/controller.rs+4
@@ -20,6 +20,10 @@ impl<'b> Controller<'b> {
2020 }
2121
2222 pub fn run(&self) -> Result<bool> {
23+ self.run_with_error_handler(default_error_handler)
24+ }
25+
26+ pub fn run_with_error_handler(&self, handle_error: impl Fn(&Error)) -> Result<bool> {
2327 // Do not launch the pager if NONE of the input files exist
2428 let mut paging_mode = self.config.paging_mode;
2529 if self.config.paging_mode != PagingMode::Never {
src/errors.rs+1−1
@@ -9,7 +9,7 @@ error_chain! {
99 }
1010}
1111
12−pub fn handle_error(error: &Error) {
12+pub fn default_error_handler(error: &Error) {
1313 match error {
1414 Error(ErrorKind::Io(ref io_error), _)
1515 if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>