mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 18:21:04 +00:00
Move error handling to a callback
This commit is contained in:
parent
a7338e2ea2
commit
fc1ca0875a
@ -211,7 +211,7 @@ fn main() {
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
handle_error(&error);
|
default_error_handler(&error);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
|
@ -20,6 +20,10 @@ impl<'b> Controller<'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&self) -> Result<bool> {
|
pub fn run(&self) -> Result<bool> {
|
||||||
|
self.run_with_error_handler(default_error_handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_with_error_handler(&self, handle_error: impl Fn(&Error)) -> Result<bool> {
|
||||||
// Do not launch the pager if NONE of the input files exist
|
// Do not launch the pager if NONE of the input files exist
|
||||||
let mut paging_mode = self.config.paging_mode;
|
let mut paging_mode = self.config.paging_mode;
|
||||||
if self.config.paging_mode != PagingMode::Never {
|
if self.config.paging_mode != PagingMode::Never {
|
||||||
|
@ -9,7 +9,7 @@ error_chain! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_error(error: &Error) {
|
pub fn default_error_handler(error: &Error) {
|
||||||
match error {
|
match error {
|
||||||
Error(ErrorKind::Io(ref io_error), _)
|
Error(ErrorKind::Io(ref io_error), _)
|
||||||
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
|
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user