1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::{error::Error, fmt::Display};

use redis::RedisError;

#[derive(Debug)]
pub struct JobError;

impl Display for JobError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        Display::fmt("An error occurred while processing the job", f)
    }
}

impl Error for JobError {}

#[derive(Debug)]
pub enum JobQueueError {
    MalformedJob,
    #[cfg(feature = "redis")]
    RedisError(RedisError),
}

impl Display for JobQueueError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            JobQueueError::MalformedJob => write!(f, "Malformed job"),
            #[cfg(feature = "redis")]
            JobQueueError::RedisError(error) => error.fmt(f),
        }
    }
}

impl Error for JobQueueError {}

#[cfg(feature = "redis")]
impl From<RedisError> for JobQueueError {
    fn from(value: RedisError) -> Self {
        Self::RedisError(value)
    }
}