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 #[error("IO error: {0}")]
74 IoError(#[from] std::io::Error),
75}
76
77#[derive(Error, Debug)]
79pub enum WorkerStateError {
80 #[error("Worker not started, did you forget to call worker.start()")]
82 NotStarted,
83 #[error("Worker already started")]
85 AlreadyStarted,
86 #[error("Worker is not running")]
88 NotRunning,
89 #[error("Worker is not paused")]
91 NotPaused,
92 #[error("Worker is shutting down")]
94 ShuttingDown,
95 #[error("Worker provided with invalid state {0}")]
97 InvalidState(String),
98}