on v0.15.0 help sign in
bat/src/error.rs
37 lines 1.0 kB history raw
1use error_chain::error_chain;
2use std::io::Write;
4error_chain! {
5 foreign_links {
6 Clap(::clap::Error) #[cfg(feature = "application")];
7 Io(::std::io::Error);
8 SyntectError(::syntect::LoadingError);
9 ParseIntError(::std::num::ParseIntError);
10 GlobParsingError(::globset::Error);
11 SerdeYamlError(::serde_yaml::Error);
12 }
15pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
16 use ansi_term::Colour::Red;
18 match error {
19 Error(ErrorKind::Io(ref io_error), _)
20 if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
21 {
22 ::std::process::exit(0);
23 }
24 Error(ErrorKind::SerdeYamlError(_), _) => {
25 writeln!(
26 output,
27 "{}: Error while parsing metadata.yaml file: {}",
28 Red.paint("[bat error]"),
29 error
30 )
31 .ok();
32 }
33 _ => {
34 writeln!(output, "{}: {}", Red.paint("[bat error]"), error).ok();
35 }
36 };