Skip to main content

cdk_common/pub_sub/
error.rs

1//! Error types for the pub-sub module.
2
3use tokio::sync::mpsc::error::TrySendError;
4
5#[derive(thiserror::Error, Debug)]
6/// Error
7pub enum Error {
8    /// No subscription found
9    #[error("Subscription not found")]
10    NoSubscription,
11
12    /// Parsing error
13    #[error("Parsing Error {0}")]
14    ParsingError(String),
15
16    /// Internal error
17    #[error("Internal")]
18    Internal(Box<dyn std::error::Error + Send + Sync>),
19
20    /// Internal error
21    #[error("Internal error {0}")]
22    InternalStr(String),
23
24    /// Not supported
25    #[error("Not supported")]
26    NotSupported,
27
28    /// A terminal transport error that must not be retried
29    #[error("Terminal error {0}")]
30    Terminal(String),
31
32    /// Channel is full
33    #[error("Channel is full")]
34    ChannelFull,
35
36    /// Channel is closed
37    #[error("Channel is close")]
38    ChannelClosed,
39}
40
41impl<T> From<TrySendError<T>> for Error {
42    fn from(value: TrySendError<T>) -> Self {
43        match value {
44            TrySendError::Closed(_) => Error::ChannelClosed,
45            TrySendError::Full(_) => Error::ChannelFull,
46        }
47    }
48}