From b4ed9cd6893088af5103ec4e18552669aa52eb93 Mon Sep 17 00:00:00 2001 From: rabite Date: Mon, 18 Feb 2019 17:30:02 +0100 Subject: preview v3 --- src/fail.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/fail.rs (limited to 'src/fail.rs') diff --git a/src/fail.rs b/src/fail.rs new file mode 100644 index 0000000..791435b --- /dev/null +++ b/src/fail.rs @@ -0,0 +1,43 @@ +use failure; + +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 = "Channel failed: {}", error)] + ChannelTryRecvError{#[cause] error: std::sync::mpsc::TryRecvError}, + #[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 } +} + +impl From for HError { + fn from(error: std::io::Error) -> Self { + HError::IoError { error: error } + } +} + +impl From for HError { + fn from(error: failure::Error) -> Self { + HError::Error { error: error } + } +} + +impl From for HError { + fn from(error: std::sync::mpsc::TryRecvError) -> Self { + HError::ChannelTryRecvError { error: error } + } +} + +impl From> for HError { + fn from(_: std::sync::PoisonError) -> Self { + HError::MutexError + } +} -- cgit v1.2.3