on v0.17.1 help sign in
bat/src/error.rs
52 lines 1.6 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 }
14 errors {
15 UndetectedSyntax(input: String) {
16 description("unable to detect syntax"),
17 display("unable to detect syntax for {}", input)
18 }
19 UnknownSyntax(name: String) {
20 description("unknown syntax"),
21 display("unknown syntax: '{}'", name)
22 }
23 InvalidPagerValueBat {
24 description("invalid value `bat` for pager property"),
25 display("Use of bat as a pager is disallowed in order to avoid infinite recursion problems")
26 }
27 }
30pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
31 use ansi_term::Colour::Red;
33 match error {
34 Error(ErrorKind::Io(ref io_error), _)
35 if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
36 {
37 ::std::process::exit(0);
38 }
39 Error(ErrorKind::SerdeYamlError(_), _) => {
40 writeln!(
41 output,
42 "{}: Error while parsing metadata.yaml file: {}",
43 Red.paint("[bat error]"),
44 error
45 )
46 .ok();
47 }
48 _ => {
49 writeln!(output, "{}: {}", Red.paint("[bat error]"), error).ok();
50 }
51 };