Skip to main content

celers_beat/
config.rs

1//! Schedule error types and configuration
2//!
3//! Contains the core error type and related configuration types.
4
5use thiserror::Error;
6
7/// Schedule errors
8#[derive(Debug, Error)]
9pub enum ScheduleError {
10    #[error("Invalid schedule: {0}")]
11    Invalid(String),
12
13    #[error("Not implemented: {0}")]
14    NotImplemented(String),
15
16    #[error("Parsing error: {0}")]
17    Parse(String),
18
19    #[error("Persistence error: {0}")]
20    Persistence(String),
21}
22
23impl ScheduleError {
24    /// Check if error is an invalid schedule configuration
25    pub fn is_invalid(&self) -> bool {
26        matches!(self, ScheduleError::Invalid(_))
27    }
28
29    /// Check if error is a not-implemented feature
30    pub fn is_not_implemented(&self) -> bool {
31        matches!(self, ScheduleError::NotImplemented(_))
32    }
33
34    /// Check if error is a parsing error
35    pub fn is_parse(&self) -> bool {
36        matches!(self, ScheduleError::Parse(_))
37    }
38
39    /// Check if error is a persistence error
40    pub fn is_persistence(&self) -> bool {
41        matches!(self, ScheduleError::Persistence(_))
42    }
43
44    /// Check if this error is retryable
45    ///
46    /// Persistence errors are retryable (transient I/O issues).
47    /// Invalid schedules, parse errors, and not-implemented features are not retryable.
48    pub fn is_retryable(&self) -> bool {
49        matches!(self, ScheduleError::Persistence(_))
50    }
51
52    /// Get the error category as a string
53    pub fn category(&self) -> &'static str {
54        match self {
55            ScheduleError::Invalid(_) => "invalid",
56            ScheduleError::NotImplemented(_) => "not_implemented",
57            ScheduleError::Parse(_) => "parse",
58            ScheduleError::Persistence(_) => "persistence",
59        }
60    }
61}