@@ -1,42 +1,52 @@
1−use error_chain::error_chain;
21use std::io::Write;
2+use thiserror::Error;
33
4−error_chain! {
5− foreign_links {
6− Clap(::clap::Error) #[cfg(feature = "minimal-application")];
7− Io(::std::io::Error);
8− SyntectError(::syntect::LoadingError);
9− ParseIntError(::std::num::ParseIntError);
10− GlobParsingError(::globset::Error);
11− SerdeYamlError(::serde_yaml::Error);
4+#[derive(Error, Debug)]
5+pub enum Error {
6+ #[error(transparent)]
7+ Io(#[from] ::std::io::Error),
8+ #[error(transparent)]
9+ SyntectError(#[from] ::syntect::LoadingError),
10+ #[error(transparent)]
11+ ParseIntError(#[from] ::std::num::ParseIntError),
12+ #[error(transparent)]
13+ GlobParsingError(#[from] ::globset::Error),
14+ #[error(transparent)]
15+ SerdeYamlError(#[from] ::serde_yaml::Error),
16+ #[error("unable to detect syntax for {0}")]
17+ UndetectedSyntax(String),
18+ #[error("unknown syntax: '{0}'")]
19+ UnknownSyntax(String),
20+ #[error("Unknown style '{0}'")]
21+ UnknownStyle(String),
22+ #[error("Use of bat as a pager is disallowed in order to avoid infinite recursion problems")]
23+ InvalidPagerValueBat,
24+ #[error("{0}")]
25+ Msg(String),
26+}
27+
28+impl From<&'static str> for Error {
29+ fn from(s: &'static str) -> Self {
30+ Error::Msg(s.to_owned())
1231 }
32+}
1333
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− }
34+impl From<String> for Error {
35+ fn from(s: String) -> Self {
36+ Error::Msg(s)
2737 }
2838}
2939
40+pub type Result<T> = std::result::Result<T, Error>;
41+
3042pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
3143 use ansi_term::Colour::Red;
3244
3345 match error {
34− Error(ErrorKind::Io(ref io_error), _)
35− if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
36− {
46+ Error::Io(ref io_error) if io_error.kind() == ::std::io::ErrorKind::BrokenPipe => {
3747 ::std::process::exit(0);
3848 }
39− Error(ErrorKind::SerdeYamlError(_), _) => {
49+ Error::SerdeYamlError(_) => {
4050 writeln!(
4151 output,
4252 "{}: Error while parsing metadata.yaml file: {}",