diff options
author | rabite <rabite@posteo.de> | 2019-03-16 14:35:32 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-03-16 14:35:32 +0100 |
commit | 33a9562379b9d6fdd7be19ce20b3a5ac1fa7e1c7 (patch) | |
tree | ceb2a79a8cbc7e22430d8645527339f284d4dfc3 /src/fail.rs | |
parent | 45203cff36eced24ce7a7c34bae386ad16ef9ca0 (diff) |
some error handling modifications
Diffstat (limited to 'src/fail.rs')
-rw-r--r-- | src/fail.rs | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/src/fail.rs b/src/fail.rs index a376c09..edbd0b2 100644 --- a/src/fail.rs +++ b/src/fail.rs @@ -16,29 +16,29 @@ pub enum HError { #[fail(display = "IO error: {} ", error)] IoError{#[cause] error: std::io::Error, backtrace: Backtrace}, #[fail(display = "Mutex failed")] - MutexError, + MutexError(Backtrace), #[fail(display = "Can't lock!")] - TryLockError, + TryLockError(Backtrace), #[fail(display = "Channel failed: {}", error)] ChannelTryRecvError{#[cause] error: std::sync::mpsc::TryRecvError}, #[fail(display = "Channel failed: {}", error)] ChannelRecvError{#[cause] error: std::sync::mpsc::RecvError}, #[fail(display = "Channel failed")] - ChannelSendError, + ChannelSendError(Backtrace), #[fail(display = "Previewer failed on file: {}", file)] - PreviewFailed{file: String}, + PreviewFailed{file: String, backtrace: Backtrace}, #[fail(display = "StalePreviewer for file: {}", file)] StalePreviewError{file: String}, #[fail(display = "Failed: {}", error)] - Error{#[cause] error: failure::Error }, + Error{#[cause] error: failure::Error , backtrace: Backtrace}, #[fail(display = "Was None!")] - NoneError, + NoneError(Backtrace), #[fail(display = "Not ready yet!")] WillBeNotReady(Backtrace), #[fail(display = "No widget found")] NoWidgetError(Backtrace), #[fail(display = "Path: {:?} not in this directory: {:?}", path, dir)] - WrongDirectoryError{ path: PathBuf, dir: PathBuf }, + WrongDirectoryError{ path: PathBuf, dir: PathBuf , backtrace: Backtrace}, #[fail(display = "Widget finnished")] PopupFinnished, #[fail(display = "No completions found")] @@ -54,11 +54,11 @@ pub enum HError { #[fail(display = "HBox ratio mismatch: {} widgets, ratio is {:?}", wnum, ratio)] HBoxWrongRatioError{ wnum: usize, ratio: Vec<usize> }, #[fail(display = "Got wrong widget: {}! Wanted: {}", got, wanted)] - WrongWidgetError{got: String, wanted: String}, + WrongWidgetError{got: String, wanted: String, backtrace: Backtrace}, #[fail(display = "Strip Prefix Error: {}", error)] - StripPrefixError{#[cause] error: std::path::StripPrefixError}, + StripPrefixError{#[cause] error: std::path::StripPrefixError, backtrace: Backtrace}, #[fail(display = "INofify failed: {}", error)] - INotifyError{#[cause] error: notify::Error}, + INotifyError{#[cause] error: notify::Error, backtrace: Backtrace}, #[fail(display = "Tags not loaded yet")] TagsNotLoadedYetError, #[fail(display = "Input cancelled!")] @@ -81,7 +81,8 @@ impl HError { } pub fn wrong_widget<T>(got: &str, wanted: &str) -> HResult<T> { Err(HError::WrongWidgetError{ got: got.to_string(), - wanted: wanted.to_string()}) + wanted: wanted.to_string(), + backtrace: Backtrace::new()}) } pub fn popup_finnished<T>() -> HResult<T> { Err(HError::PopupFinnished) @@ -98,6 +99,16 @@ impl HError { pub fn undefined_key<T>(key: Key) -> HResult<T> { Err(HError::WidgetUndefinedKeyError { key: key }) } + pub fn wrong_directory<T>(path: PathBuf, dir: PathBuf) -> HResult<T> { + Err(HError::WrongDirectoryError{ path: path, + dir: dir, + backtrace: Backtrace::new() }) + } + pub fn preview_failed<T>(file: &crate::files::File) -> HResult<T> { + let name = file.name.clone(); + Err(HError::PreviewFailed{ file: name, + backtrace: Backtrace::new() }) + } } @@ -122,7 +133,7 @@ pub trait ErrorLog where Self: Sized { impl<T> ErrorLog for HResult<T> { fn log(self) { if let Err(err) = self { - eprintln!("{:?}", err); + // eprintln!("{:?}", err); put_log(&err).ok(); } } @@ -140,7 +151,7 @@ impl<T> ErrorLog for HResult<T> { impl From<std::io::Error> for HError { fn from(error: std::io::Error) -> Self { - dbg!(&error); + // dbg!(&error); let err = HError::IoError { error: error, backtrace: Backtrace::new() }; put_log(&err).ok(); err @@ -149,8 +160,8 @@ impl From<std::io::Error> for HError { impl From<failure::Error> for HError { fn from(error: failure::Error) -> Self { - dbg!(&error); - let err = HError::Error { error: error }; + // dbg!(&error); + let err = HError::Error { error: error, backtrace: Backtrace::new() }; put_log(&err).ok(); err } @@ -158,7 +169,7 @@ impl From<failure::Error> for HError { impl From<std::sync::mpsc::TryRecvError> for HError { fn from(error: std::sync::mpsc::TryRecvError) -> Self { - dbg!(&error); + // dbg!(&error); let err = HError::ChannelTryRecvError { error: error }; put_log(&err).ok(); err @@ -167,7 +178,7 @@ impl From<std::sync::mpsc::TryRecvError> for HError { impl From<std::sync::mpsc::RecvError> for HError { fn from(error: std::sync::mpsc::RecvError) -> Self { - dbg!(&error); + // dbg!(&error); let err = HError::ChannelRecvError { error: error }; put_log(&err).ok(); err @@ -177,7 +188,7 @@ impl From<std::sync::mpsc::RecvError> for HError { impl<T> From<std::sync::mpsc::SendError<T>> for HError { fn from(error: std::sync::mpsc::SendError<T>) -> Self { dbg!(&error); - let err = HError::ChannelSendError; + let err = HError::ChannelSendError(Backtrace::new()); put_log(&err).ok(); err } @@ -185,8 +196,8 @@ impl<T> From<std::sync::mpsc::SendError<T>> for HError { impl<T> From<std::sync::PoisonError<T>> for HError { fn from(_: std::sync::PoisonError<T>) -> Self { - dbg!("Poisoned Mutex"); - let err = HError::MutexError; + // dbg!("Poisoned Mutex"); + let err = HError::MutexError(Backtrace::new()); put_log(&err).ok(); err } @@ -194,8 +205,8 @@ impl<T> From<std::sync::PoisonError<T>> for HError { impl<T> From<std::sync::TryLockError<T>> for HError { fn from(error: std::sync::TryLockError<T>) -> Self { - dbg!(&error); - let err = HError::TryLockError; + // dbg!(&error); + let err = HError::TryLockError(Backtrace::new()); put_log(&err).ok(); err } @@ -204,7 +215,7 @@ impl<T> From<std::sync::TryLockError<T>> for HError { impl From<std::option::NoneError> for HError { fn from(error: std::option::NoneError) -> Self { //dbg!(&error); - let err = HError::NoneError; + let err = HError::NoneError(Backtrace::new()); //put_log(&err).ok(); err } @@ -212,8 +223,8 @@ impl From<std::option::NoneError> for HError { impl From<std::path::StripPrefixError> for HError { fn from(error: std::path::StripPrefixError) -> Self { - dbg!(&error); - let err = HError::StripPrefixError{error: error}; + // dbg!(&error); + let err = HError::StripPrefixError{error: error, backtrace: Backtrace::new() }; put_log(&err).ok(); err } @@ -221,8 +232,8 @@ impl From<std::path::StripPrefixError> for HError { impl From<notify::Error> for HError { fn from(error: notify::Error) -> Self { - dbg!(&error); - let err = HError::INotifyError{error: error}; + // dbg!(&error); + let err = HError::INotifyError{error: error, backtrace: Backtrace::new() }; put_log(&err).ok(); err } |