templar_proxy_oracle_kernel/proxy/circuit_breaker/
error.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2#[repr(u16)]
3pub enum ErrorCode {
4 TooManyBreakers = 1,
5 BreakerNotFound = 2,
6 UnexpectedBreakerId = 5,
7 InvalidPrice = 6,
8 InvalidConfiguration = 7,
9}
10
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum CircuitBreakerError {
13 TooManyBreakers,
14 BreakerNotFound { breaker_id: u32 },
15 UnexpectedBreakerId { expected: u32, actual: u32 },
16 InvalidPrice,
17 InvalidConfiguration,
18}
19
20impl CircuitBreakerError {
21 #[must_use]
22 pub const fn code(&self) -> ErrorCode {
23 match self {
24 Self::TooManyBreakers => ErrorCode::TooManyBreakers,
25 Self::BreakerNotFound { .. } => ErrorCode::BreakerNotFound,
26 Self::UnexpectedBreakerId { .. } => ErrorCode::UnexpectedBreakerId,
27 Self::InvalidPrice => ErrorCode::InvalidPrice,
28 Self::InvalidConfiguration => ErrorCode::InvalidConfiguration,
29 }
30 }
31}
32
33impl core::fmt::Display for CircuitBreakerError {
34 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
35 match self {
36 Self::TooManyBreakers => write!(f, "too many circuit breakers"),
37 Self::BreakerNotFound { breaker_id } => {
38 write!(f, "circuit breaker not found: {breaker_id}")
39 }
40 Self::UnexpectedBreakerId { expected, actual } => {
41 write!(
42 f,
43 "unexpected circuit breaker ID: expected {expected}, got {actual}"
44 )
45 }
46 Self::InvalidPrice => write!(f, "invalid price"),
47 Self::InvalidConfiguration => write!(f, "invalid circuit breaker configuration"),
48 }
49 }
50}
51
52#[cfg(feature = "std")]
53impl std::error::Error for CircuitBreakerError {}