Skip to main content

mytheclipse_queue/
error.rs

1//! Errors returned by queue and job operations.
2
3/// Errors from queue-level operations (enqueue, dequeue, etc.).
4#[derive(Debug)]
5pub enum QueueError {
6    /// A transport or backend connection error.
7    Connection(String),
8    /// The requested topic/queue does not exist or is unavailable.
9    NotFound(String),
10    /// A serialization error.
11    Serialization(String),
12    /// A timeout occurred while waiting for an operation.
13    Timeout,
14    /// The operation was rejected because of a rate limit.
15    RateLimit(String),
16}
17
18impl std::fmt::Display for QueueError {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::Connection(s) => write!(f, "queue connection error: {s}"),
22            Self::NotFound(s) => write!(f, "queue not found: {s}"),
23            Self::Serialization(s) => write!(f, "serialization error: {s}"),
24            Self::Timeout => write!(f, "queue operation timed out"),
25            Self::RateLimit(s) => write!(f, "queue rate limited: {s}"),
26        }
27    }
28}
29
30impl std::error::Error for QueueError {}
31
32/// Errors from individual job processing.
33#[derive(Debug)]
34pub enum JobError {
35    /// The job could not be acknowledged.
36    AckFailed(String),
37    /// The job could not be moved to the dead-letter queue.
38    DlqFailed(String),
39    /// The job exceeded its maximum retry count.
40    MaxRetriesExceeded,
41    /// The job payload could not be decoded.
42    InvalidPayload(String),
43}
44
45impl std::fmt::Display for JobError {
46    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47        match self {
48            Self::AckFailed(s) => write!(f, "ack failed: {s}"),
49            Self::DlqFailed(s) => write!(f, "dlq move failed: {s}"),
50            Self::MaxRetriesExceeded => write!(f, "max retries exceeded"),
51            Self::InvalidPayload(s) => write!(f, "invalid payload: {s}"),
52        }
53    }
54}
55
56impl std::error::Error for JobError {}