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("{0}")]
37    Other(String),
38}
39
40impl KojinError {
41    pub fn broker(msg: impl fmt::Display) -> Self {
42        Self::Broker(msg.to_string())
43    }
44
45    pub fn task_failed(msg: impl fmt::Display) -> Self {
46        Self::TaskFailed(msg.to_string())
47    }
48
49    pub fn result_backend(msg: impl fmt::Display) -> Self {
50        Self::ResultBackend(msg.to_string())
51    }
52}
53
54/// Convenience result alias.
55pub type TaskResult<T> = Result<T, KojinError>;