Skip to main content

do_over/
error.rs

1//! Error types for do_over policies.
2//!
3//! This module provides the [`DoOverError`] enum which wraps application errors
4//! with policy-specific failure variants.
5
6use thiserror::Error;
7
8/// Error type that wraps application errors with policy-specific failures.
9///
10/// `DoOverError<E>` allows you to distinguish between infrastructure failures
11/// (timeout, circuit open, bulkhead full) and your application's own errors.
12///
13/// # Type Parameter
14///
15/// * `E` - Your application's error type
16///
17/// # Examples
18///
19/// ```rust
20/// use do_over::error::DoOverError;
21///
22/// fn handle_error<E: std::fmt::Debug>(err: DoOverError<E>) {
23///     match err {
24///         DoOverError::Timeout => println!("Operation timed out"),
25///         DoOverError::CircuitOpen => println!("Circuit breaker is open"),
26///         DoOverError::BulkheadFull => println!("Too many concurrent requests"),
27///         DoOverError::Inner(e) => println!("Application error: {:?}", e),
28///     }
29/// }
30/// ```
31#[derive(Debug, Error)]
32pub enum DoOverError<E> {
33    /// The operation exceeded its configured timeout duration.
34    #[error("operation timed out")]
35    Timeout,
36
37    /// The circuit breaker is in the Open state and rejecting requests.
38    #[error("circuit breaker is open")]
39    CircuitOpen,
40
41    /// The bulkhead or rate limiter rejected the request due to capacity limits.
42    #[error("bulkhead rejected execution")]
43    BulkheadFull,
44
45    /// An error from the underlying operation.
46    #[error(transparent)]
47    Inner(E),
48}