ferro_queue/
error.rs

1//! Error types for the queue system.
2
3use thiserror::Error;
4
5/// Errors that can occur in the queue system.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Failed to connect to the queue backend.
9    #[error("Queue connection failed: {0}")]
10    ConnectionFailed(String),
11
12    /// Failed to serialize a job.
13    #[error("Failed to serialize job: {0}")]
14    SerializationFailed(String),
15
16    /// Failed to deserialize a job.
17    #[error("Failed to deserialize job: {0}")]
18    DeserializationFailed(String),
19
20    /// Failed to push a job to the queue.
21    #[error("Failed to push job to queue '{queue}': {message}")]
22    PushFailed {
23        /// The queue name.
24        queue: String,
25        /// The error message.
26        message: String,
27    },
28
29    /// Failed to pop a job from the queue.
30    #[error("Failed to pop job from queue '{queue}': {message}")]
31    PopFailed {
32        /// The queue name.
33        queue: String,
34        /// The error message.
35        message: String,
36    },
37
38    /// Job execution failed.
39    #[error("Job '{job}' failed: {message}")]
40    JobFailed {
41        /// The job name.
42        job: String,
43        /// The error message.
44        message: String,
45    },
46
47    /// Maximum retry attempts exceeded.
48    #[error("Job '{job}' exceeded maximum retries ({max_retries})")]
49    MaxRetriesExceeded {
50        /// The job name.
51        job: String,
52        /// Maximum retry count.
53        max_retries: u32,
54    },
55
56    /// Redis error.
57    #[error("Redis error: {0}")]
58    Redis(#[from] redis::RedisError),
59
60    /// JSON error.
61    #[error("JSON error: {0}")]
62    Json(#[from] serde_json::Error),
63
64    /// Custom error.
65    #[error("{0}")]
66    Custom(String),
67}
68
69impl Error {
70    /// Create a job failed error.
71    pub fn job_failed(job: impl Into<String>, message: impl Into<String>) -> Self {
72        Self::JobFailed {
73            job: job.into(),
74            message: message.into(),
75        }
76    }
77
78    /// Create a push failed error.
79    pub fn push_failed(queue: impl Into<String>, message: impl Into<String>) -> Self {
80        Self::PushFailed {
81            queue: queue.into(),
82            message: message.into(),
83        }
84    }
85
86    /// Create a custom error.
87    pub fn custom(message: impl Into<String>) -> Self {
88        Self::Custom(message.into())
89    }
90}
91
92impl From<String> for Error {
93    fn from(s: String) -> Self {
94        Self::Custom(s)
95    }
96}
97
98impl From<&str> for Error {
99    fn from(s: &str) -> Self {
100        Self::Custom(s.to_string())
101    }
102}