1use std::{
2 error::Error,
3 fmt::{Display, Formatter},
4};
5
6#[derive(Debug)]
7pub enum SchedulerError {
8 ScheduleDefinitionError {
9 message: String,
10 },
11 JobLockError {
12 message: String,
13 },
14 JobExecutionStateError {
15 message: String,
16 },
17 JobExecutionError {
18 source: Box<dyn std::error::Error + Send + Sync>,
19 },
20 JobExecutionPanic {
21 cause: String,
22 },
23}
24
25impl Display for SchedulerError {
26 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27 match self {
28 SchedulerError::ScheduleDefinitionError {
29 message,
30 } => {
31 write!(f, "ScheduleDefinitionError: [{message}]")
32 }
33 SchedulerError::JobLockError {
34 message,
35 } => write!(f, "JobLockError: [{message}]"),
36 SchedulerError::JobExecutionStateError {
37 message,
38 } => {
39 write!(f, "JobExecutionStateError: [{message}]")
40 }
41 SchedulerError::JobExecutionError {
42 ..
43 } => write!(f, "JobExecutionError"),
44 SchedulerError::JobExecutionPanic {
45 cause,
46 } => {
47 write!(f, "JobExecutionPanic: [{cause}]")
48 }
49 }
50 }
51}
52
53impl Error for SchedulerError {
54 fn source(&self) -> Option<&(dyn Error + 'static)> {
55 match self {
56 SchedulerError::ScheduleDefinitionError {
57 ..
58 }
59 | SchedulerError::JobLockError {
60 ..
61 }
62 | SchedulerError::JobExecutionStateError {
63 ..
64 }
65 | SchedulerError::JobExecutionPanic {
66 ..
67 } => None,
68
69 SchedulerError::JobExecutionError {
70 source,
71 } => Some(source.as_ref()),
72 }
73 }
74}