atomic_circuit_breaker/error/enum.rs
1use super::*;
2
3/// Configuration validation errors returned when building a `CircuitBreaker`.
4#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
5pub enum CircuitBreakerError {
6 /// Neither failure threshold, consecutive failure threshold, nor failure rate was enabled.
7 NoTripCondition,
8 /// A failure threshold was set to zero.
9 InvalidThreshold,
10 /// Failure rate was NaN, infinite, `<= 0.0`, or `> 1.0`.
11 InvalidFailureRate,
12 /// Sliding window duration was zero.
13 ZeroWindow,
14 /// Open cooldown duration was zero.
15 ZeroCooldown,
16 /// Half-open max probes was zero or success threshold exceeded max probes.
17 InvalidHalfOpenConfig,
18 /// Duration overflowed `u64::MAX` nanoseconds.
19 DurationOverflow,
20}
21
22/// Error returned by `CircuitBreaker::call`, distinguishing rejections from inner errors.
23#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
24pub enum CallError<E> {
25 /// Circuit was open or half-open probe capacity was saturated.
26 Rejected {
27 /// Current circuit state at rejection time.
28 state: CircuitState,
29 /// Nanoseconds remaining before cooldown expires (`0` if half-open saturated).
30 retry_after_ns: u64,
31 },
32 /// The wrapped operation executed and returned an inner error.
33 Inner(E),
34}