acton_htmx/jobs/
error.rs

1//! Job-related error types.
2
3use thiserror::Error;
4
5/// Result type for job operations.
6pub type JobResult<T> = Result<T, JobError>;
7
8/// Errors that can occur during job processing.
9#[derive(Debug, Error)]
10pub enum JobError {
11    /// Job execution failed.
12    #[error("job execution failed: {0}")]
13    ExecutionFailed(String),
14
15    /// Job timed out.
16    #[error("job timed out after {0:?}")]
17    Timeout(std::time::Duration),
18
19    /// Job exceeded maximum retry attempts.
20    #[error("job failed after {0} retries")]
21    MaxRetriesExceeded(u32),
22
23    /// Serialization error.
24    #[error("serialization error: {0}")]
25    SerializationError(#[from] serde_json::Error),
26
27    /// Redis error.
28    #[cfg(feature = "redis")]
29    #[error("redis error: {0}")]
30    RedisError(#[from] redis::RedisError),
31
32    /// Job not found.
33    #[error("job not found: {0}")]
34    NotFound(String),
35
36    /// Job queue is full.
37    #[error("job queue is full (max: {0})")]
38    QueueFull(usize),
39
40    /// Job agent not available.
41    #[error("job agent not available")]
42    AgentUnavailable,
43
44    /// Other error.
45    #[error("{0}")]
46    Other(String),
47}
48
49impl From<String> for JobError {
50    fn from(s: String) -> Self {
51        Self::ExecutionFailed(s)
52    }
53}
54
55impl From<&str> for JobError {
56    fn from(s: &str) -> Self {
57        Self::ExecutionFailed(s.to_string())
58    }
59}
60
61impl From<anyhow::Error> for JobError {
62    fn from(err: anyhow::Error) -> Self {
63        Self::ExecutionFailed(err.to_string())
64    }
65}