From dbf310a0643c95ae88f3af9013891fd0060a503a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 8 Oct 2019 19:34:43 +0200 Subject: Remove error module, as it is not used --- src/errors.rs | 89 ----------------------------------------------------------- src/lib.rs | 1 - 2 files changed, 90 deletions(-) delete mode 100644 src/errors.rs diff --git a/src/errors.rs b/src/errors.rs deleted file mode 100644 index 7b66319..0000000 --- a/src/errors.rs +++ /dev/null @@ -1,89 +0,0 @@ -use backtrace::Backtrace; -use std::error::Error; -use std::fmt; - -#[derive(Debug)] -pub struct KhError { - msg: String, - backtrace: Backtrace, - cause: Option>, -} - -impl KhError { - pub fn new(msg: &str, cause: Option>) -> KhError { - KhError { - msg: msg.to_string(), - #[cfg(debug_assertions)] - backtrace: backtrace_strip_foreign(Backtrace::new()), - #[cfg(not(debug_assertions))] - backtrace: Backtrace::new_unresolved(), - cause, - } - } -} - -#[cfg(debug_assertions)] -fn backtrace_strip_foreign(backtrace: Backtrace) -> Backtrace { - use backtrace::BacktraceFrame; - let backtrace: Vec = backtrace.into(); - backtrace - .into_iter() - .filter(|frame| { - frame - .symbols() - .iter() - .map(|symbol| { - symbol - .name() - .and_then(|name| name.as_str()) - .map_or(false, |name| name.contains("khaleesi")) - }) - .any(|x| x) - }) - .collect::>() - .into() -} - -impl fmt::Display for KhError { - #[cfg(debug_assertions)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}\n{:?}", self.msg, self.backtrace) - } - #[cfg(not(debug_assertions))] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.msg) - } -} - -impl Error for KhError { - fn source(&self) -> Option<&(dyn Error + 'static)> { - // lol idunno - self.cause.as_ref().map(|cause| &**cause) - } -} - -impl From<&str> for KhError { - fn from(e: &str) -> KhError { - KhError::new(e, None) - } -} - -impl From for KhError { - fn from(e: String) -> KhError { - KhError::new(&e, None) - } -} - -impl From for KhError { - fn from(e: std::path::StripPrefixError) -> KhError { - let description = e.to_string(); - KhError::new(&description, Some(Box::new(e))) - } -} - -impl From<::std::io::Error> for KhError { - fn from(e: ::std::io::Error) -> KhError { - let description = e.to_string(); - KhError::new(&description, Some(Box::new(e))) - } -} diff --git a/src/lib.rs b/src/lib.rs index a49914c..8ead59a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,6 @@ lazy_static! { pub mod component; pub mod duration; -pub mod errors; pub mod property; pub mod time; pub mod timezone; -- cgit v1.2.3