crius/
error.rs

1use std::fmt;
2use std::error::Error;
3
4/// This error type describes the possible failures that can occur
5/// while attempting to run a circuit breaker command.
6pub enum CriusError {
7    /// Error variant returned in case of an open breaker.
8    ExecutionRejected,
9
10    /// Error variant returned in case of invalid configuration (e.g.
11    /// parameters that cause duration calculations to overflow).
12    InvalidConfig,
13}
14
15const REJECTED: &str = "Rejected command execution due to open breaker";
16const INVALID: &str = "Provided circuit breaker configuration was invalid";
17
18impl fmt::Display for CriusError {
19    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20        match *self {
21            CriusError::ExecutionRejected => write!(f, "{}", REJECTED),
22            CriusError::InvalidConfig => write!(f, "{}", INVALID),
23        }
24    }
25}
26
27impl fmt::Debug for CriusError {
28    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29        <Self as fmt::Display>::fmt(self, f)
30    }
31}
32
33impl Error for CriusError {
34    fn description(&self) -> &str {
35        match *self {
36            CriusError::ExecutionRejected => REJECTED,
37            CriusError::InvalidConfig => INVALID,
38        }
39    }
40}