2019-02-18 17:30:02 +01:00
|
|
|
use failure;
|
2019-02-26 10:17:51 +01:00
|
|
|
use failure::Fail;
|
2019-02-18 17:30:02 +01:00
|
|
|
|
2019-02-26 22:31:33 +01:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2019-02-18 17:30:02 +01:00
|
|
|
pub type HResult<T> = Result<T, HError>;
|
|
|
|
|
|
|
|
#[derive(Fail, Debug)]
|
|
|
|
pub enum HError {
|
|
|
|
#[fail(display = "IO error: {}", error)]
|
|
|
|
IoError{#[cause] error: std::io::Error},
|
|
|
|
#[fail(display = "Mutex failed")]
|
|
|
|
MutexError,
|
2019-02-21 21:41:52 +01:00
|
|
|
#[fail(display = "Can't lock!")]
|
|
|
|
TryLockError,
|
2019-02-18 17:30:02 +01:00
|
|
|
#[fail(display = "Channel failed: {}", error)]
|
|
|
|
ChannelTryRecvError{#[cause] error: std::sync::mpsc::TryRecvError},
|
2019-02-21 21:41:52 +01:00
|
|
|
#[fail(display = "Channel failed: {}", error)]
|
|
|
|
ChannelRecvError{#[cause] error: std::sync::mpsc::RecvError},
|
|
|
|
#[fail(display = "Channel failed")]
|
|
|
|
ChannelSendError,
|
2019-02-18 17:30:02 +01:00
|
|
|
#[fail(display = "Previewer failed on file: {}", file)]
|
|
|
|
PreviewFailed{file: String},
|
|
|
|
#[fail(display = "StalePreviewer for file: {}", file)]
|
|
|
|
StalePreviewError{file: String},
|
|
|
|
#[fail(display = "Failed: {}", error)]
|
2019-02-21 21:41:52 +01:00
|
|
|
Error{#[cause] error: failure::Error },
|
|
|
|
#[fail(display = "Was None!")]
|
|
|
|
NoneError,
|
|
|
|
#[fail(display = "Not ready yet!")]
|
|
|
|
WillBeNotReady,
|
|
|
|
#[fail(display = "No widget found")]
|
2019-02-26 22:31:33 +01:00
|
|
|
NoWidgetError,
|
|
|
|
#[fail(display = "Path: {:?} not in this directory: {:?}", path, dir)]
|
|
|
|
WrongDirectoryError{ path: PathBuf, dir: PathBuf }
|
2019-02-18 17:30:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for HError {
|
|
|
|
fn from(error: std::io::Error) -> Self {
|
2019-02-21 21:41:52 +01:00
|
|
|
dbg!(&error);
|
2019-02-18 17:30:02 +01:00
|
|
|
HError::IoError { error: error }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<failure::Error> for HError {
|
|
|
|
fn from(error: failure::Error) -> Self {
|
2019-02-21 21:41:52 +01:00
|
|
|
dbg!(&error);
|
2019-02-18 17:30:02 +01:00
|
|
|
HError::Error { error: error }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::sync::mpsc::TryRecvError> for HError {
|
|
|
|
fn from(error: std::sync::mpsc::TryRecvError) -> Self {
|
2019-02-21 21:41:52 +01:00
|
|
|
dbg!(&error);
|
2019-02-18 17:30:02 +01:00
|
|
|
HError::ChannelTryRecvError { error: error }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 21:41:52 +01:00
|
|
|
impl From<std::sync::mpsc::RecvError> for HError {
|
|
|
|
fn from(error: std::sync::mpsc::RecvError) -> Self {
|
|
|
|
dbg!(&error);
|
|
|
|
HError::ChannelRecvError { error: error }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<std::sync::mpsc::SendError<T>> for HError {
|
|
|
|
fn from(error: std::sync::mpsc::SendError<T>) -> Self {
|
|
|
|
dbg!(&error);
|
|
|
|
HError::ChannelSendError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 17:30:02 +01:00
|
|
|
impl<T> From<std::sync::PoisonError<T>> for HError {
|
|
|
|
fn from(_: std::sync::PoisonError<T>) -> Self {
|
2019-02-21 21:41:52 +01:00
|
|
|
dbg!("Poisoned Mutex");
|
2019-02-18 17:30:02 +01:00
|
|
|
HError::MutexError
|
|
|
|
}
|
|
|
|
}
|
2019-02-21 21:41:52 +01:00
|
|
|
|
|
|
|
impl<T> From<std::sync::TryLockError<T>> for HError {
|
|
|
|
fn from(error: std::sync::TryLockError<T>) -> Self {
|
|
|
|
dbg!(&error);
|
|
|
|
HError::TryLockError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::option::NoneError> for HError {
|
|
|
|
fn from(error: std::option::NoneError) -> Self {
|
|
|
|
dbg!(&error);
|
|
|
|
HError::NoneError
|
|
|
|
}
|
|
|
|
}
|