2020-03-21 19:35:04 +01:00
|
|
|
use error_chain::error_chain;
|
2020-04-25 12:25:25 +02:00
|
|
|
use std::io::Write;
|
2020-03-21 19:35:04 +01:00
|
|
|
|
|
|
|
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-05-15 17:52:33 -07:00
|
|
|
|
|
|
|
errors {
|
|
|
|
UndetectedSyntax(input: String) {
|
|
|
|
description("unable to detect syntax"),
|
|
|
|
display("unable to detect syntax for {}", input)
|
|
|
|
}
|
|
|
|
UnknownSyntax(name: String) {
|
|
|
|
description("unknown syntax"),
|
|
|
|
display("unknown syntax: '{}'", name)
|
|
|
|
}
|
2020-10-25 02:13:57 -07:00
|
|
|
InvalidPagerValueBat {
|
|
|
|
description("invalid value `bat` for pager property"),
|
|
|
|
display("Use of bat as a pager is disallowed in order to avoid infinite recursion problems")
|
|
|
|
}
|
2020-05-15 17:52:33 -07:00
|
|
|
}
|
2020-03-21 19:35:04 +01:00
|
|
|
}
|
|
|
|
|
2020-04-25 12:25:25 +02:00
|
|
|
pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
|
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(_), _) => {
|
2020-04-25 12:25:25 +02:00
|
|
|
writeln!(
|
|
|
|
output,
|
2020-04-21 15:50:46 +02:00
|
|
|
"{}: Error while parsing metadata.yaml file: {}",
|
|
|
|
Red.paint("[bat error]"),
|
|
|
|
error
|
2020-04-25 12:25:25 +02:00
|
|
|
)
|
|
|
|
.ok();
|
2020-04-21 15:50:46 +02:00
|
|
|
}
|
2020-03-21 19:35:04 +01:00
|
|
|
_ => {
|
2020-04-25 12:25:25 +02:00
|
|
|
writeln!(output, "{}: {}", Red.paint("[bat error]"), error).ok();
|
2020-03-21 19:35:04 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|