Skip to main content

kojin_core/
error.rs

1use std::fmt;
2
3/// Core error type for Kojin.
4#[derive(Debug, thiserror::Error)]
5pub enum KojinError {
6    #[error("serialization error: {0}")]
7    Serialization(#[from] serde_json::Error),
8
9    #[error("broker error: {0}")]
10    Broker(String),
11
12    #[error("task not found: {0}")]
13    TaskNotFound(String),
14
15    #[error("task failed: {0}")]
16    TaskFailed(String),
17
18    #[error("task timeout after {0:?}")]
19    Timeout(std::time::Duration),
20
21    #[error("task revoked: {0}")]
22    Revoked(String),
23
24    #[error("result backend error: {0}")]
25    ResultBackend(String),
26
27    #[error("queue not found: {0}")]
28    QueueNotFound(String),
29
30    #[error("codec error: {0}")]
31    Codec(String),
32
33    #[error("shutdown in progress")]
34    ShutdownInProgress,
35
36    #[error("duplicate task: {0}")]
37    Duplicate(String),
38
39    #[error("{0}")]
40    Other(String),
41}
42
43impl KojinError {
44    pub fn broker(msg: impl fmt::Display) -> Self {
45        Self::Broker(msg.to_string())
46    }
47
48    pub fn task_failed(msg: impl fmt::Display) -> Self {
49        Self::TaskFailed(msg.to_string())
50    }
51
52    pub fn result_backend(msg: impl fmt::Display) -> Self {
53        Self::ResultBackend(msg.to_string())
54    }
55}
56
57/// Convenience result alias.
58pub type TaskResult<T> = Result<T, KojinError>;