1#[derive(Debug, thiserror::Error)]
2pub enum DurableError {
3 #[error("database error: {0}")]
4 Db(#[from] sea_orm::DbErr),
5
6 #[error("serialization error: {0}")]
7 Json(#[from] serde_json::Error),
8
9 #[error("{0}")]
10 Custom(String),
11
12 #[error("task locked by another worker: {0}")]
13 StepLocked(String),
14
15 #[error("timeout: {0}")]
16 Timeout(String),
17
18 #[error("workflow paused: {0}")]
19 Paused(String),
20
21 #[error("workflow cancelled: {0}")]
22 Cancelled(String),
23
24 #[error("max recovery attempts exceeded for workflow {0}")]
25 MaxRecoveryExceeded(String),
26}
27
28impl DurableError {
29 pub fn custom(msg: impl Into<String>) -> Self {
30 Self::Custom(msg.into())
31 }
32
33 pub fn is_step_locked(&self) -> bool {
34 matches!(self, Self::StepLocked(_))
35 }
36
37 pub fn is_paused(&self) -> bool {
38 matches!(self, Self::Paused(_))
39 }
40
41 pub fn is_cancelled(&self) -> bool {
42 matches!(self, Self::Cancelled(_))
43 }
44
45 pub fn is_max_recovery_exceeded(&self) -> bool {
46 matches!(self, Self::MaxRecoveryExceeded(_))
47 }
48}