summaryrefslogtreecommitdiffstats
path: root/src/fail.rs
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-02-18 17:30:02 +0100
committerrabite <rabite@posteo.de>2019-02-18 17:30:02 +0100
commitb4ed9cd6893088af5103ec4e18552669aa52eb93 (patch)
tree20c61700925265c3dc20a277569bd6b7e892e2e5 /src/fail.rs
parentad44f6f2fc586bbf0cf8c131467e93df58295b2d (diff)
preview v3
Diffstat (limited to 'src/fail.rs')
-rw-r--r--src/fail.rs43
1 files changed, 43 insertions, 0 deletions
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<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,
+ #[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<std::io::Error> for HError {
+ fn from(error: std::io::Error) -> Self {
+ HError::IoError { error: error }
+ }
+}
+
+impl From<failure::Error> for HError {
+ fn from(error: failure::Error) -> Self {
+ HError::Error { error: error }
+ }
+}
+
+impl From<std::sync::mpsc::TryRecvError> for HError {
+ fn from(error: std::sync::mpsc::TryRecvError) -> Self {
+ HError::ChannelTryRecvError { error: error }
+ }
+}
+
+impl<T> From<std::sync::PoisonError<T>> for HError {
+ fn from(_: std::sync::PoisonError<T>) -> Self {
+ HError::MutexError
+ }
+}