2020-03-21 19:35:04 +01:00
|
|
|
use error_chain::error_chain;
|
|
|
|
|
|
|
|
error_chain! {
|
|
|
|
foreign_links {
|
2020-03-30 13:18:41 -07:00
|
|
|
Clap(::clap::Error) #[cfg(feature = "application")];
|
|
|
|
Io(::std::io::Error);
|
|
|
|
SyntectError(::syntect::LoadingError);
|
|
|
|
ParseIntError(::std::num::ParseIntError);
|
|
|
|
GlobParsingError(::globset::Error);
|
2020-04-21 15:50:46 +02:00
|
|
|
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) {
|
2020-04-21 15:50:46 +02:00
|
|
|
use ansi_term::Colour::Red;
|
|
|
|
|
2020-03-21 19:35:04 +01:00
|
|
|
match error {
|
|
|
|
Error(ErrorKind::Io(ref io_error), _)
|
2020-03-30 13:18:41 -07:00
|
|
|
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
|
2020-03-21 19:35:04 +01:00
|
|
|
{
|
2020-03-30 13:18:41 -07:00
|
|
|
::std::process::exit(0);
|
2020-03-21 19:35:04 +01:00
|
|
|
}
|
2020-04-21 15:50:46 +02: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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|