aboutsummaryrefslogtreecommitdiff
path: root/net/src/error.rs
blob: 36561285a487c62be4730c826602037b62804d58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use thiserror::Error as ThisError;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(ThisError, Debug)]
pub enum Error {
    #[error(transparent)]
    IO(#[from] std::io::Error),

    #[error("Try from endpoint Error")]
    TryFromEndpoint,

    #[error("invalid address {0}")]
    InvalidAddress(String),

    #[error("invalid path {0}")]
    InvalidPath(String),

    #[error("invalid endpoint {0}")]
    InvalidEndpoint(String),

    #[error("Encode error: {0}")]
    Encode(String),

    #[error("Decode error: {0}")]
    Decode(String),

    #[error("Parse endpoint error {0}")]
    ParseEndpoint(String),

    #[error("Timeout Error")]
    Timeout,

    #[error("Channel Send Error: {0}")]
    ChannelSend(String),

    #[error(transparent)]
    ChannelRecv(#[from] async_channel::RecvError),

    #[cfg(feature = "ws")]
    #[error("Ws Error: {0}")]
    WsError(#[from] async_tungstenite::tungstenite::Error),

    #[cfg(feature = "tls")]
    #[error("Tls Error: {0}")]
    Rustls(#[from] karyon_async_rustls::rustls::Error),

    #[cfg(feature = "tls")]
    #[error("Invalid DNS Name: {0}")]
    InvalidDnsNameError(#[from] rustls_pki_types::InvalidDnsNameError),

    #[error(transparent)]
    KaryonCore(#[from] karyon_core::Error),
}

impl<T> From<async_channel::SendError<T>> for Error {
    fn from(error: async_channel::SendError<T>) -> Self {
        Error::ChannelSend(error.to_string())
    }
}