aster_forge_tasks/
error.rs1pub type Result<T> = std::result::Result<T, TaskCoreError>;
5
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8pub enum TaskCoreError {
9 #[error("{0}")]
11 Codec(String),
12 #[error("{0}")]
14 InvalidValue(String),
15 #[error("{0}")]
17 Io(String),
18 #[error("background task lease lost for task #{task_id} with token {processing_token}")]
20 LeaseLost {
21 task_id: i64,
23 processing_token: i64,
25 },
26 #[error(
28 "background task lease renewal timed out for task #{task_id} with token {processing_token}"
29 )]
30 LeaseRenewalTimedOut {
31 task_id: i64,
33 processing_token: i64,
35 },
36 #[error(
38 "background task worker shutdown requested for task #{task_id} with token {processing_token}"
39 )]
40 WorkerShutdownRequested {
41 task_id: i64,
43 processing_token: i64,
45 },
46}
47
48impl TaskCoreError {
49 pub fn codec(message: impl Into<String>) -> Self {
51 Self::Codec(message.into())
52 }
53
54 pub fn invalid_value(message: impl Into<String>) -> Self {
56 Self::InvalidValue(message.into())
57 }
58
59 pub fn io(message: impl Into<String>) -> Self {
61 Self::Io(message.into())
62 }
63
64 pub const fn is_task_lease_lost(&self) -> bool {
66 matches!(self, Self::LeaseLost { .. })
67 }
68
69 pub const fn is_task_lease_renewal_timed_out(&self) -> bool {
71 matches!(self, Self::LeaseRenewalTimedOut { .. })
72 }
73
74 pub const fn is_task_worker_shutdown_requested(&self) -> bool {
76 matches!(self, Self::WorkerShutdownRequested { .. })
77 }
78}