use failure; use failure::Error; use failure::{Fail, ResultExt}; pub type HResult = Result; #[derive(Fail, Debug)] pub enum HError { #[fail(display = "IO error: {}", error)] IoError{#[cause] error: std::io::Error}, #[fail(display = "Mutex failed")] MutexError, #[fail(display = "Can't lock!")] 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, #[fail(display = "Previewer failed on file: {}", file)] PreviewFailed{file: String}, #[fail(display = "StalePreviewer for file: {}", file)] StalePreviewError{file: String}, #[fail(display = "Failed: {}", error)] Error{#[cause] error: failure::Error }, #[fail(display = "Was None!")] NoneError, #[fail(display = "Not ready yet!")] WillBeNotReady, #[fail(display = "No widget found")] NoWidgetError } impl From for HError { fn from(error: std::io::Error) -> Self { dbg!(&error); HError::IoError { error: error } } } impl From for HError { fn from(error: failure::Error) -> Self { dbg!(&error); HError::Error { error: error } } } impl From for HError { fn from(error: std::sync::mpsc::TryRecvError) -> Self { dbg!(&error); HError::ChannelTryRecvError { error: error } } } impl From for HError { fn from(error: std::sync::mpsc::RecvError) -> Self { dbg!(&error); HError::ChannelRecvError { error: error } } } impl From> for HError { fn from(error: std::sync::mpsc::SendError) -> Self { dbg!(&error); HError::ChannelSendError } } impl From> for HError { fn from(_: std::sync::PoisonError) -> Self { dbg!("Poisoned Mutex"); HError::MutexError } } impl From> for HError { fn from(error: std::sync::TryLockError) -> Self { dbg!(&error); HError::TryLockError } } impl From for HError { fn from(error: std::option::NoneError) -> Self { dbg!(&error); HError::NoneError } }