use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("backend error: {0}")]
Backend(String),
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("job not found: {0}")]
NotFound(String),
#[error("job already dead: {0}")]
AlreadyDead(String),
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum JobError {
#[error("{0}")]
Retry(String),
#[error("{0}")]
Discard(String),
}
impl JobError {
pub fn retry(msg: impl ToString) -> Self {
Self::Retry(msg.to_string())
}
pub fn discard(msg: impl ToString) -> Self {
Self::Discard(msg.to_string())
}
pub fn is_discard(&self) -> bool {
matches!(self, Self::Discard(_))
}
}
impl From<String> for JobError {
fn from(s: String) -> Self { Self::Retry(s) }
}
impl From<&str> for JobError {
fn from(s: &str) -> Self { Self::Retry(s.to_owned()) }
}
pub type JobResult = std::result::Result<(), JobError>;