1use std::{error::Error as StdError, time::Duration};
2use thiserror::Error;
3
4pub type BoxDynError = Box<dyn StdError + 'static + Send + Sync>;
6#[derive(Error, Debug)]
9#[error("AbortError: {source}")]
10pub struct AbortError {
11 #[source]
12 source: BoxDynError,
13}
14impl AbortError {
15 pub fn new<E: Into<BoxDynError>>(err: E) -> Self {
17 AbortError { source: err.into() }
18 }
19}
20
21#[derive(Error, Debug)]
24#[error("RetryError: {source}")]
25pub struct RetryAfterError {
26 #[source]
27 source: BoxDynError,
28 duration: Duration,
29}
30
31impl RetryAfterError {
32 pub fn new<E: Into<BoxDynError>>(err: E, duration: Duration) -> Self {
34 RetryAfterError {
35 source: err.into(),
36 duration,
37 }
38 }
39
40 pub fn get_duration(&self) -> Duration {
42 self.duration
43 }
44}
45
46#[derive(Error, Debug)]
48#[error("DeferredError: {source}")]
49pub struct DeferredError {
50 #[source]
51 source: BoxDynError,
52}
53
54#[derive(Error, Debug)]
56pub enum WorkerError {
57 #[error("Failed to consume task stream: {0}")]
59 StreamError(BoxDynError),
60 #[error("Heartbeat error: {0}")]
62 HeartbeatError(BoxDynError),
63 #[error("Failed to handle the new state: {0}")]
65 StateError(WorkerStateError),
66 #[error("Worker stopped and gracefully exited")]
68 GracefulExit,
69 #[error("Worker panicked: {0}")]
71 PanicError(String),
72}
73
74#[derive(Error, Debug)]
76pub enum WorkerStateError {
77 #[error("Worker not started, did you forget to call worker.start()")]
79 NotStarted,
80 #[error("Worker already started")]
82 AlreadyStarted,
83 #[error("Worker is not running")]
85 NotRunning,
86 #[error("Worker is not paused")]
88 NotPaused,
89 #[error("Worker is shutting down")]
91 ShuttingDown,
92 #[error("Worker provided with invalid state {0}")]
94 InvalidState(String),
95}