llm_incident_manager/scheduler/
error.rs

1//! Error types for the scheduler module
2
3use crate::error::AppError;
4
5/// Result type for scheduler operations
6pub type SchedulerResult<T> = std::result::Result<T, SchedulerError>;
7
8/// Errors that can occur in scheduler operations
9#[derive(Debug, thiserror::Error)]
10pub enum SchedulerError {
11    /// Scheduler failed to start
12    #[error("Failed to start scheduler: {0}")]
13    StartupFailed(String),
14
15    /// Scheduler failed to shutdown
16    #[error("Failed to shutdown scheduler: {0}")]
17    ShutdownFailed(String),
18
19    /// Job creation failed
20    #[error("Failed to create job: {0}")]
21    JobCreationFailed(String),
22
23    /// Job not found
24    #[error("Job not found: {0}")]
25    JobNotFound(String),
26
27    /// Job execution failed
28    #[error("Job execution failed: {0}")]
29    JobExecutionFailed(String),
30
31    /// Invalid cron expression
32    #[error("Invalid cron expression: {0}")]
33    InvalidCronExpression(String),
34
35    /// Configuration error
36    #[error("Configuration error: {0}")]
37    ConfigurationError(String),
38
39    /// Internal scheduler error
40    #[error("Internal scheduler error: {0}")]
41    InternalError(String),
42
43    /// Job already exists
44    #[error("Job already exists: {0}")]
45    JobAlreadyExists(String),
46}
47
48impl From<SchedulerError> for AppError {
49    fn from(err: SchedulerError) -> Self {
50        match err {
51            SchedulerError::JobNotFound(msg) => AppError::NotFound(msg),
52            SchedulerError::InvalidCronExpression(msg) | SchedulerError::ConfigurationError(msg) => {
53                AppError::Configuration(msg)
54            }
55            _ => AppError::Internal(err.to_string()),
56        }
57    }
58}
59
60impl From<tokio_cron_scheduler::JobSchedulerError> for SchedulerError {
61    fn from(err: tokio_cron_scheduler::JobSchedulerError) -> Self {
62        SchedulerError::InternalError(format!("tokio-cron-scheduler error: {}", err))
63    }
64}