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
use crate::login::LoginCredentials;
use crate::message::IRCParseError;
use crate::transport::Transport;
use std::sync::Arc;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error<T: Transport, L: LoginCredentials> {
#[error("Underlying transport failed to connect: {0}")]
ConnectError(Arc<T::ConnectError>),
#[error("Underlying transport failed to connect: Connect timed out")]
ConnectTimeout,
#[error("Error received from incoming stream of messages: {0}")]
IncomingError(Arc<T::IncomingError>),
#[error("Error received while trying to send message(s) out: {0}")]
OutgoingError(Arc<T::OutgoingError>),
#[error("Incoming message was not valid IRC: {0}")]
IRCParseError(IRCParseError),
#[error("Failed to get login credentials to log in with: {0}")]
LoginError(Arc<L::Error>),
#[error("Received RECONNECT command by IRC server")]
ReconnectCmd,
#[error("Did not receive a PONG back after sending PING")]
PingTimeout,
#[error("Remote server unexpectedly closed connection")]
RemoteUnexpectedlyClosedConnection,
}
impl<T: Transport, L: LoginCredentials> Clone for Error<T, L> {
fn clone(&self) -> Self {
match self {
Error::ConnectError(e) => Error::ConnectError(Arc::clone(e)),
Error::ConnectTimeout => Error::ConnectTimeout,
Error::IncomingError(e) => Error::IncomingError(Arc::clone(e)),
Error::OutgoingError(e) => Error::OutgoingError(Arc::clone(e)),
Error::IRCParseError(e) => Error::IRCParseError(*e),
Error::LoginError(e) => Error::LoginError(Arc::clone(e)),
Error::ReconnectCmd => Error::ReconnectCmd,
Error::PingTimeout => Error::PingTimeout,
Error::RemoteUnexpectedlyClosedConnection => Error::RemoteUnexpectedlyClosedConnection,
}
}
}