diidi_travel_common_queue/
error.rs1use thiserror::Error;
2
3pub type QueueResult<T> = Result<T, QueueError>;
4
5#[derive(Debug, Error)]
6pub enum QueueError {
7 #[error("invalid queue configuration: {0}")]
8 InvalidConfig(String),
9
10 #[error("queue provider '{0}' is not registered with the factory")]
11 ProviderNotRegistered(String),
12
13 #[error("queue provider '{provider}' does not support feature '{feature}'")]
14 Unsupported { provider: &'static str, feature: &'static str },
15
16 #[error("queue serialization error: {0}")]
17 Serialization(String),
18
19 #[error("queue backend connection error: {0}")]
20 Connection(String),
21
22 #[error("queue backend error: {0}")]
23 Backend(String),
24
25 #[error("queue operation timed out")]
26 Timeout,
27}
28
29impl QueueError {
30 pub fn invalid_config(msg: impl Into<String>) -> Self {
31 Self::InvalidConfig(msg.into())
32 }
33
34 pub fn backend(msg: impl Into<String>) -> Self {
35 Self::Backend(msg.into())
36 }
37
38 pub fn connection(msg: impl Into<String>) -> Self {
39 Self::Connection(msg.into())
40 }
41
42 pub fn serialization(msg: impl Into<String>) -> Self {
43 Self::Serialization(msg.into())
44 }
45
46 pub fn unsupported(provider: &'static str, feature: &'static str) -> Self {
47 Self::Unsupported { provider, feature }
48 }
49
50 pub fn is_transient(&self) -> bool {
51 matches!(self, Self::Connection(_) | Self::Timeout)
52 }
53}