1use std::fmt;
2
3#[derive(Clone, Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum Error {
7 Config(String),
10 Connect(String),
12 Auth(String),
15 Timeout(String),
17 Encryption(String),
19 Signing(String),
22 GaveUp(String),
24 NotConnected,
26 Full,
28 Closed,
30 Panicked,
32 Encode(String),
34 Decode(String),
36}
37
38impl fmt::Display for Error {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Self::Config(why) => write!(f, "invalid configuration: {why}"),
42 Self::Connect(why) => write!(f, "cannot connect: {why}"),
43 Self::Auth(why) => write!(f, "authentication refused: {why}"),
44 Self::Timeout(why) => write!(f, "timed out: {why}"),
45 Self::Encryption(why) => write!(f, "end-to-end encryption failed: {why}"),
46 Self::Signing(why) => write!(f, "cannot sign: {why}"),
47 Self::GaveUp(why) => write!(f, "gave up reconnecting: {why}"),
48 Self::NotConnected => f.write_str("not connected"),
49 Self::Full => f.write_str("the send queue is full"),
50 Self::Closed => f.write_str("the client is closed"),
51 Self::Panicked => f.write_str("the handler panicked"),
52 Self::Encode(why) => write!(f, "cannot encode the message: {why}"),
53 Self::Decode(why) => write!(f, "cannot decode the payload: {why}"),
54 }
55 }
56}
57
58impl std::error::Error for Error {}