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