1use deadpool_sqlite::InteractError;
2
3pub type Result<T, E = Error> = std::result::Result<T, E>;
5
6#[derive(thiserror::Error, Debug)]
8pub enum Error {
9 #[error("Migration error: {0}")]
11 Migration(#[from] rusqlite_migration::Error),
12 #[error("Error opening database: {0}")]
14 OpenDatabase(eyre::Report),
15 #[error("Error acquiring database connection: {0}")]
17 PoolError(#[from] deadpool_sqlite::PoolError),
18 #[error("Database error: {0}")]
20 Database(#[from] rusqlite::Error),
21 #[error("Unexpected value type for {1}: {0}")]
23 ColumnType(#[source] rusqlite::Error, &'static str),
24 #[error("Internal error: {0}")]
26 Panic(#[from] tokio::task::JoinError),
27 #[error("Internal error: {0}")]
29 DbInteract(String),
30 #[error("Job not found")]
32 NotFound,
33 #[error("Invalid job state {0}")]
35 InvalidJobState(String),
36 #[error("Error decoding job run info {0}")]
38 InvalidJobRunInfo(serde_json::Error),
39 #[error("Error processing payload: {0}")]
41 PayloadError(serde_json::Error),
42 #[error("Timestamp {0} out of range")]
44 TimestampOutOfRange(&'static str),
45 #[error("Attempted to finish already-finished job")]
47 JobAlreadyConsumed,
48 #[error("Timed out")]
51 Timeout,
52 #[error("Job is running")]
54 JobRunning,
55 #[error("Job is finished")]
57 JobFinished,
58 #[error("Job expired")]
60 Expired,
61 #[error("Worker {0} not found")]
63 WorkerNotFound(u64),
64 #[error("Queue closed unexpectedly")]
66 QueueClosed,
67 #[error("Invalid schedule specification")]
69 InvalidSchedule,
70 #[error("Recurring job {0} already exists")]
72 RecurringJobAlreadyExists(String),
73}
74
75impl Error {
76 pub fn is_update_too_late(&self) -> bool {
78 matches!(self, Error::JobRunning | Error::JobFinished)
79 }
80}
81
82impl From<InteractError> for Error {
83 fn from(e: InteractError) -> Self {
84 Error::DbInteract(e.to_string())
85 }
86}
87
88impl Error {
89 pub(crate) fn open_database(err: impl Into<eyre::Report>) -> Self {
90 Error::OpenDatabase(err.into())
91 }
92}