summaryrefslogtreecommitdiffstats
path: root/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/errors.rs b/src/errors.rs
index a0f7e5eb..ff5682b9 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -2,20 +2,20 @@ use error_chain::error_chain;
error_chain! {
foreign_links {
- Clap(::clap::Error);
- Io(::std::io::Error);
- SyntectError(::syntect::LoadingError);
- ParseIntError(::std::num::ParseIntError);
- GlobParsingError(::globset::Error);
+ Clap(clap::Error);
+ Io(std::io::Error);
+ SyntectError(syntect::LoadingError);
+ ParseIntError(std::num::ParseIntError);
+ GlobParsingError(globset::Error);
}
}
pub fn default_error_handler(error: &Error) {
match error {
Error(ErrorKind::Io(ref io_error), _)
- if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
+ if io_error.kind() == std::io::ErrorKind::BrokenPipe =>
{
- ::std::process::exit(0);
+ std::process::exit(0);
}
_ => {
use ansi_term::Colour::Red;
@@ -23,3 +23,36 @@ pub fn default_error_handler(error: &Error) {
}
};
}
+
+// Mock out a type for clap::Error if we aren't pulling in a dependency on clap.
+//
+// This can be removed after migrating away from error_chain to some modern
+// derive-based error library such as thiserror, in favor of:
+//
+// #[derive(Error)]
+// pub enum Error {
+// #[cfg(feature = "application")]
+// Clap(clap::Error),
+// ...
+// }
+//
+#[cfg(not(feature = "application"))]
+mod clap {
+ use std::fmt::{self, Debug, Display};
+
+ pub struct Error(());
+
+ impl Display for Error {
+ fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
+ unreachable!()
+ }
+ }
+
+ impl Debug for Error {
+ fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
+ unreachable!()
+ }
+ }
+
+ impl std::error::Error for Error {}
+}