Skip to main content

systemprompt_database/resilience/
error.rs

1//! The error type the resilience layer itself produces.
2
3use std::time::Duration;
4
5/// A failure surfaced by the resilience layer wrapping a caller's operation.
6///
7/// [`ResilienceError::Inner`] carries the caller's own error `E` unchanged
8/// (after retries are exhausted). The other variants are produced by the guard
9/// itself and the caller is expected to map them into its domain error enum.
10#[derive(Debug, thiserror::Error)]
11pub enum ResilienceError<E> {
12    /// The circuit breaker is open; the call was rejected without being
13    /// attempted.
14    #[error("circuit breaker '{key}' is open; failing fast")]
15    CircuitOpen { key: String },
16
17    /// The bulkhead is saturated; the call was rejected to protect capacity.
18    #[error("bulkhead '{key}' is saturated ({limit} concurrent permits in use)")]
19    BulkheadFull { key: String, limit: usize },
20
21    /// The operation exceeded its per-attempt timeout on every retry.
22    #[error("operation timed out after {after:?}")]
23    Timeout { after: Duration },
24
25    /// The caller's operation failed (retries exhausted, or a permanent
26    /// failure).
27    #[error(transparent)]
28    Inner(#[from] E),
29}