bat/src/error.rs

35 lines
952 B
Rust
Raw Normal View History

2020-03-21 19:35:04 +01:00
use error_chain::error_chain;
error_chain! {
foreign_links {
2020-03-30 22:18:41 +02:00
Clap(::clap::Error) #[cfg(feature = "application")];
Io(::std::io::Error);
SyntectError(::syntect::LoadingError);
ParseIntError(::std::num::ParseIntError);
GlobParsingError(::globset::Error);
SerdeYamlError(::serde_yaml::Error);
2020-03-21 19:35:04 +01:00
}
}
2020-03-21 19:51:59 +01:00
pub fn default_error_handler(error: &Error) {
use ansi_term::Colour::Red;
2020-03-21 19:35:04 +01:00
match error {
Error(ErrorKind::Io(ref io_error), _)
2020-03-30 22:18:41 +02:00
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
2020-03-21 19:35:04 +01:00
{
2020-03-30 22:18:41 +02:00
::std::process::exit(0);
2020-03-21 19:35:04 +01:00
}
Error(ErrorKind::SerdeYamlError(_), _) => {
eprintln!(
"{}: Error while parsing metadata.yaml file: {}",
Red.paint("[bat error]"),
error
);
}
2020-03-21 19:35:04 +01:00
_ => {
eprintln!("{}: {}", Red.paint("[bat error]"), error);
}
};
}