Skip to content

Commit

Permalink
Implement std::error::Error for SRCError
Browse files Browse the repository at this point in the history
  • Loading branch information
gklijs committed Jun 20, 2021
1 parent d01a58d commit ba93de9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
use std::error::Error;
use std::fmt;
use std::fmt::Display;

use failure::Fail;

/// Error struct which makes it easy to know if the resulting error is also preserved in the cache
/// or not. And whether trying it again might not cause an error.
#[derive(Debug, PartialEq, Fail)]
#[derive(Debug, PartialEq)]
pub struct SRCError {
pub error: String,
pub cause: Option<String>,
pub retriable: bool,
pub cached: bool,
}

/// Implements standard error so error handling can be simplified
impl Error for SRCError {}

/// Implements clone so when an error is returned from the cache, a copy can be returned
impl Clone for SRCError {
fn clone(&self) -> SRCError {
let side = match &self.cause {
Some(v) => Some(v.clone()),
None => None,
};
SRCError {
error: self.error.clone(),
cause: side,
cause: self.cause.as_ref().cloned(),
retriable: self.retriable,
cached: self.cached,
}
Expand Down

0 comments on commit ba93de9

Please sign in to comment.