diff options
author | rabite <rabite@posteo.de> | 2019-03-25 02:53:59 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-03-25 02:53:59 +0100 |
commit | 3888f49aebb911ac6b2d83f9f78f2feb092069a8 (patch) | |
tree | d33a0fe09dd7fd31e6daebef4ec8559f292026ab /src/fail.rs | |
parent | fd366a26dcddfc50d54ec0481a8f6e4848356b32 (diff) |
load metadata and file-count asynchronously
Diffstat (limited to 'src/fail.rs')
-rw-r--r-- | src/fail.rs | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/src/fail.rs b/src/fail.rs index 039002a..55cd5aa 100644 --- a/src/fail.rs +++ b/src/fail.rs @@ -11,42 +11,44 @@ use crate::foldview::LogEntry; pub type HResult<T> = Result<T, HError>; -#[derive(Fail, Debug)] +#[derive(Fail, Debug, Clone)] pub enum HError { - #[fail(display = "IO error: {} ", error)] - IoError{#[cause] error: std::io::Error, backtrace: Backtrace}, + #[fail(display = "IO error: {} ", _0)] + IoError(String), #[fail(display = "Mutex failed")] - MutexError(Backtrace), + MutexError, #[fail(display = "Can't lock!")] - TryLockError(Backtrace), + TryLockError, #[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(Backtrace), + ChannelSendError, #[fail(display = "Previewer failed on file: {}", file)] - PreviewFailed{file: String, backtrace: Backtrace}, + PreviewFailed{file: String}, #[fail(display = "StalePreviewer for file: {}", file)] StalePreviewError{file: String}, #[fail(display = "Accessed stale value")] - StaleError(Backtrace), - #[fail(display = "Failed: {}", error)] - Error{#[cause] error: failure::Error , backtrace: Backtrace}, + StaleError, + #[fail(display = "Failed: {}", _0)] + Error(String), #[fail(display = "Was None!")] - NoneError(Backtrace), + NoneError, #[fail(display = "Not ready yet!")] - WillBeNotReady(Backtrace), + WillBeNotReady, #[fail(display = "Not ready yet!")] - AsyncNotReadyError(Backtrace), + AsyncNotReadyError, + #[fail(display = "Async is stale!")] + AsyncStaleError, #[fail(display = "Value has already been taken!")] - AsyncAlreadyTakenError(Backtrace), + AsyncAlreadyTakenError, #[fail(display = "Async Error: {}", _0)] AsyncError(String), #[fail(display = "No widget found")] - NoWidgetError(Backtrace), + NoWidgetError, #[fail(display = "Path: {:?} not in this directory: {:?}", path, dir)] - WrongDirectoryError{ path: PathBuf, dir: PathBuf , backtrace: Backtrace}, + WrongDirectoryError{ path: PathBuf, dir: PathBuf}, #[fail(display = "Widget finnished")] PopupFinnished, #[fail(display = "No completions found")] @@ -54,7 +56,7 @@ pub enum HError { #[fail(display = "No more history")] NoHistoryError, #[fail(display = "No core for widget")] - NoWidgetCoreError(Backtrace), + NoWidgetCoreError, #[fail(display = "No header for widget")] NoHeaderError, #[fail(display = "You wanted this!")] @@ -62,11 +64,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, backtrace: Backtrace}, + WrongWidgetError{got: String, wanted: String}, #[fail(display = "Strip Prefix Error: {}", error)] - StripPrefixError{#[cause] error: std::path::StripPrefixError, backtrace: Backtrace}, - #[fail(display = "INofify failed: {}", error)] - INotifyError{#[cause] error: notify::Error, backtrace: Backtrace}, + StripPrefixError{#[cause] error: std::path::StripPrefixError}, + #[fail(display = "INofify failed: {}", _0)] + INotifyError(String), #[fail(display = "Tags not loaded yet")] TagsNotLoadedYetError, #[fail(display = "Input cancelled!")] @@ -79,6 +81,8 @@ pub enum HError { TerminalResizedError, #[fail(display = "{}", _0)] Log(String), + #[fail(display = "Metadata already processed")] + MetadataProcessedError } impl HError { @@ -92,12 +96,12 @@ impl HError { Err(HError::HBoxWrongRatioError{ wnum: wnum, ratio: ratio }) } pub fn no_widget<T>() -> HResult<T> { - Err(HError::NoWidgetError(Backtrace::new())) + Err(HError::NoWidgetError) } pub fn wrong_widget<T>(got: &str, wanted: &str) -> HResult<T> { Err(HError::WrongWidgetError{ got: got.to_string(), - wanted: wanted.to_string(), - backtrace: Backtrace::new()}) + wanted: wanted.to_string() }) + } pub fn popup_finnished<T>() -> HResult<T> { Err(HError::PopupFinnished) @@ -116,13 +120,13 @@ impl HError { } pub fn wrong_directory<T>(path: PathBuf, dir: PathBuf) -> HResult<T> { Err(HError::WrongDirectoryError{ path: path, - dir: dir, - backtrace: Backtrace::new() }) + dir: dir }) + } pub fn preview_failed<T>(file: &crate::files::File) -> HResult<T> { let name = file.name.clone(); - Err(HError::PreviewFailed{ file: name, - backtrace: Backtrace::new() }) + Err(HError::PreviewFailed{ file: name }) + } pub fn terminal_resized<T>() -> HResult<T> { @@ -130,20 +134,24 @@ impl HError { } pub fn stale<T>() -> HResult<T> { - Err(HError::StaleError(Backtrace::new())) + Err(HError::StaleError) } pub fn async_not_ready<T>() -> HResult<T> { - Err(HError::AsyncNotReadyError(Backtrace::new())) + Err(HError::AsyncNotReadyError) } pub fn async_taken<T>() -> HResult<T> { - Err(HError::AsyncAlreadyTakenError(Backtrace::new())) + Err(HError::AsyncAlreadyTakenError) } pub fn async_error<T>(error: &HError) -> HResult<T> { Err(HError::AsyncError(format!("{}", error))) } + + pub fn metadata_processed<T>() -> HResult<T> { + Err(HError::MetadataProcessedError) + } } @@ -195,7 +203,7 @@ impl<T> ErrorLog for HResult<T> { impl From<std::io::Error> for HError { fn from(error: std::io::Error) -> Self { // dbg!(&error); - let err = HError::IoError { error: error, backtrace: Backtrace::new() }; + let err = HError::IoError(format!("{}", error)); put_log(&err).ok(); err } @@ -204,7 +212,7 @@ 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, backtrace: Backtrace::new() }; + let err = HError::Error(format!("{}", error)); put_log(&err).ok(); err } @@ -231,7 +239,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(Backtrace::new()); + let err = HError::ChannelSendError; put_log(&err).ok(); err } @@ -240,7 +248,7 @@ 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(Backtrace::new()); + let err = HError::MutexError; put_log(&err).ok(); err } @@ -249,7 +257,7 @@ 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(Backtrace::new()); + let err = HError::TryLockError; put_log(&err).ok(); err } @@ -258,7 +266,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(Backtrace::new()); + let err = HError::NoneError; //put_log(&err).ok(); err } @@ -267,7 +275,7 @@ 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, backtrace: Backtrace::new() }; + let err = HError::StripPrefixError{error: error }; put_log(&err).ok(); err } @@ -276,7 +284,7 @@ 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, backtrace: Backtrace::new() }; + let err = HError::INotifyError(format!("{}", error)); put_log(&err).ok(); err } |