kaspa_notify/
error.rs

1use async_channel::{RecvError, SendError, TrySendError};
2use thiserror::Error;
3
4pub type BoxedStdError = Box<(dyn std::error::Error + Sync + std::marker::Send + 'static)>;
5
6#[derive(Clone, Debug, Error)]
7pub enum Error {
8    #[error("Error: {0}")]
9    General(String),
10
11    #[error("channel receive error")]
12    ChannelRecvError,
13
14    #[error("channel send error")]
15    ChannelSendError,
16
17    #[error("object already stopped")]
18    AlreadyStoppedError,
19
20    #[error("connection closed")]
21    ConnectionClosed,
22
23    #[error("event type disabled")]
24    EventTypeDisabled,
25
26    #[error("Invalid event type: {0}")]
27    InvalidEventType(String),
28
29    #[error(transparent)]
30    AddressError(#[from] crate::address::error::Error),
31}
32
33impl From<BoxedStdError> for Error {
34    fn from(err: BoxedStdError) -> Self {
35        Error::General(err.to_string())
36    }
37}
38
39impl<T> From<SendError<T>> for Error {
40    fn from(_: SendError<T>) -> Self {
41        Error::ChannelSendError
42    }
43}
44
45impl<T> From<TrySendError<T>> for Error {
46    fn from(_: TrySendError<T>) -> Self {
47        Error::ChannelSendError
48    }
49}
50
51impl From<RecvError> for Error {
52    fn from(_: RecvError) -> Self {
53        Error::ChannelRecvError
54    }
55}
56
57pub type Result<T> = std::result::Result<T, Error>;