rust_rabbit/
error.rs

1use thiserror::Error;
2
3/// Main error type for the rust-rabbit library
4#[derive(Error, Debug)]
5pub enum RabbitError {
6    #[error("Connection error: {0}")]
7    Connection(#[from] lapin::Error),
8
9    #[error("Serialization error: {0}")]
10    Serialization(#[from] serde_json::Error),
11
12    #[error("Serialization error: {0}")]
13    SerializationError(String),
14
15    #[error("Configuration error: {0}")]
16    Configuration(String),
17
18    #[error("Channel error: {0}")]
19    ChannelError(String),
20
21    #[error("Consumer error: {0}")]
22    Consumer(String),
23
24    #[error("Publisher error: {0}")]
25    Publisher(String),
26
27    #[error("Retry exhausted: {0}")]
28    RetryExhausted(String),
29
30    #[error("Health check failed: {0}")]
31    HealthCheck(String),
32
33    #[error("Timeout error: {0}")]
34    Timeout(String),
35
36    #[error("IO error: {0}")]
37    Io(#[from] std::io::Error),
38
39    #[error("Generic error: {0}")]
40    Generic(#[from] anyhow::Error),
41}
42
43/// Extended error type for advanced patterns (Phase 2)
44#[derive(Error, Debug)]
45pub enum RustRabbitError {
46    // Core errors
47    #[error("Rabbit error: {0}")]
48    Rabbit(#[from] RabbitError),
49
50    // Request-Response pattern errors
51    #[error("Request timeout")]
52    RequestTimeout,
53
54    #[error("Response channel closed")]
55    ResponseChannelClosed,
56
57    // Saga pattern errors
58    #[error("Saga not found")]
59    SagaNotFound,
60
61    #[error("Saga executor not found for action type: {0}")]
62    SagaExecutorNotFound(String),
63
64    #[error("Saga compensation failed")]
65    SagaCompensationFailed,
66
67    // Event sourcing errors
68    #[error("Event sequence error - events must be in order")]
69    EventSequenceError,
70
71    #[error("Unknown event type: {0}")]
72    UnknownEventType(String),
73
74    #[error("Aggregate not found")]
75    AggregateNotFound,
76
77    #[error("Snapshot creation failed")]
78    SnapshotCreationFailed,
79
80    // Priority queue errors
81    #[error("Queue is full")]
82    QueueFull,
83
84    #[error("Queue not found: {0}")]
85    QueueNotFound(String),
86
87    #[error("Invalid priority value: {0}")]
88    InvalidPriority(u8),
89
90    // Deduplication errors
91    #[error("Duplicate message detected")]
92    DuplicateMessage,
93
94    #[error("Deduplication store error: {0}")]
95    DeduplicationStore(String),
96
97    // General async errors
98    #[error("Channel send error")]
99    ChannelSendError,
100
101    #[error("Task join error: {0}")]
102    TaskJoinError(String),
103
104    #[error("Lock poisoned")]
105    LockPoisoned,
106}
107
108/// Result type alias for the rust-rabbit library
109pub type Result<T> = std::result::Result<T, RabbitError>;