1use chik_protocol::{NodeType, ProtocolMessageTypes};
2use thiserror::Error;
3use tokio::sync::oneshot::error::RecvError;
4
5#[derive(Debug, Error)]
6pub enum ClientError {
7 #[error("SSL error: {0}")]
8 Ssl(#[from] chik_ssl::Error),
9
10 #[error("TLS method is not supported")]
11 UnsupportedTls,
12
13 #[error("Streamable error: {0}")]
14 Streamable(#[from] chik_traits::Error),
15
16 #[error("WebSocket error: {0}")]
17 WebSocket(#[from] tungstenite::Error),
18
19 #[cfg(feature = "native-tls")]
20 #[error("Native TLS error: {0}")]
21 NativeTls(#[from] native_tls::Error),
22
23 #[cfg(feature = "rustls")]
24 #[error("Rustls error: {0}")]
25 Rustls(#[from] rustls::Error),
26
27 #[cfg(feature = "rustls")]
28 #[error("Missing pkcs8 private key")]
29 MissingPkcs8Key,
30
31 #[cfg(feature = "rustls")]
32 #[error("Missing CA cert")]
33 MissingCa,
34
35 #[error("Unexpected message received with type {0:?}")]
36 UnexpectedMessage(ProtocolMessageTypes),
37
38 #[error("Expected response with type {0:?}, found {1:?}")]
39 InvalidResponse(Vec<ProtocolMessageTypes>, ProtocolMessageTypes),
40
41 #[error("Failed to receive message")]
42 Recv(#[from] RecvError),
43
44 #[error("IO error: {0}")]
45 Io(#[from] std::io::Error),
46
47 #[error("Missing response during handshake")]
48 MissingHandshake,
49
50 #[error("Expected node type {0:?}, but found {1:?}")]
51 WrongNodeType(NodeType, NodeType),
52
53 #[error("Expected network {0}, but found {1}")]
54 WrongNetwork(String, String),
55
56 #[error("The peer is banned")]
57 BannedPeer,
58}