1use rand::rngs::SysError;
2use thiserror::Error as ThisError;
3
4pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(ThisError, Debug)]
8pub enum Error {
9 #[error(transparent)]
10 IO(#[from] std::io::Error),
11
12 #[error("Unsupported Protocol: {0}")]
13 UnsupportedProtocol(String),
14
15 #[error("Unsupported Endpoint: {0}")]
16 UnsupportedEndpoint(String),
17
18 #[error("Invalid Endpoint: {0}")]
19 InvalidEndpoint(String),
20
21 #[error("PeerID Try From PublicKey")]
22 PeerIDTryFromPublicKey,
23
24 #[error("PeerID Try From String")]
25 PeerIDTryFromString,
26
27 #[error("Invalid Message: {0}")]
28 InvalidMsg(String),
29
30 #[error("Incompatible Peer")]
31 IncompatiblePeer,
32
33 #[error("Incompatible Version: {0}")]
34 IncompatibleVersion(String),
35
36 #[error("Timeout")]
37 Timeout,
38
39 #[error("Parse Error: {0}")]
40 ParseError(String),
41
42 #[error("Config Error: {0}")]
43 Config(String),
44
45 #[error("Peer Shutdown")]
46 PeerShutdown,
47
48 #[error("Invalid Pong Msg")]
49 InvalidPongMsg,
50
51 #[error("Peer Already Connected")]
52 PeerAlreadyConnected,
53
54 #[error("Access Denied")]
55 AccessDenied,
56
57 #[error("Peer Not Found: {0}")]
58 PeerNotFound(String),
59
60 #[error("Discovery Error: {0}")]
61 Discovery(String),
62
63 #[error("Lookup Error: {0}")]
64 Lookup(String),
65
66 #[error("Channel Send Error: {0}")]
67 ChannelSend(String),
68
69 #[error(transparent)]
70 ChannelRecv(#[from] async_channel::RecvError),
71
72 #[error(transparent)]
73 ParseIntError(#[from] std::num::ParseIntError),
74
75 #[error(transparent)]
76 Base64Decode(#[from] base64::DecodeError),
77
78 #[error(transparent)]
79 BincodeDecode(#[from] bincode::error::DecodeError),
80
81 #[error(transparent)]
82 BincodeEncode(#[from] bincode::error::EncodeError),
83
84 #[error(transparent)]
85 ParseFloatError(#[from] std::num::ParseFloatError),
86
87 #[error(transparent)]
88 SemverError(#[from] semver::Error),
89
90 #[error(transparent)]
91 Yasna(#[from] yasna::ASN1Error),
92
93 #[error(transparent)]
94 Rand(#[from] SysError),
95
96 #[error(transparent)]
97 X509Parser(#[from] x509_parser::error::X509Error),
98
99 #[error(transparent)]
100 Rcgen(#[from] rcgen::Error),
101
102 #[cfg(feature = "smol")]
103 #[error("TLS Error: {0}")]
104 Rustls(#[from] futures_rustls::rustls::Error),
105
106 #[cfg(feature = "tokio")]
107 #[error("TLS Error: {0}")]
108 Rustls(#[from] tokio_rustls::rustls::Error),
109
110 #[error("Invalid DNS Name: {0}")]
111 InvalidDnsNameError(#[from] rustls_pki_types::InvalidDnsNameError),
112
113 #[error(transparent)]
114 KaryonCore(#[from] karyon_core::error::Error),
115
116 #[error(transparent)]
117 KaryonNet(#[from] karyon_net::Error),
118
119 #[error(transparent)]
120 KaryonEventEmitter(#[from] karyon_eventemitter::error::Error),
121}
122
123impl<T> From<async_channel::SendError<T>> for Error {
124 fn from(error: async_channel::SendError<T>) -> Self {
125 Error::ChannelSend(error.to_string())
126 }
127}