1use crate::login::LoginCredentials;
2use crate::message::IRCParseError;
3use crate::transport::Transport;
4use std::sync::Arc;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
9pub enum Error<T: Transport, L: LoginCredentials> {
10 #[error("Underlying transport failed to connect: {0}")]
12 ConnectError(Arc<T::ConnectError>),
13 #[error("Underlying transport failed to connect: Connect timed out")]
15 ConnectTimeout,
16 #[error("Error received from incoming stream of messages: {0}")]
18 IncomingError(Arc<T::IncomingError>),
19 #[error("Error received while trying to send message(s) out: {0}")]
21 OutgoingError(Arc<T::OutgoingError>),
22 #[error("Incoming message was not valid IRC: {0}")]
24 IRCParseError(IRCParseError),
25 #[error("Failed to get login credentials to log in with: {0}")]
27 LoginError(Arc<L::Error>),
28 #[error("Received RECONNECT command by IRC server")]
30 ReconnectCmd,
31 #[error("Did not receive a PONG back after sending PING")]
33 PingTimeout,
34 #[error("Remote server unexpectedly closed connection")]
36 RemoteUnexpectedlyClosedConnection,
37}
38
39impl<T: Transport, L: LoginCredentials> Clone for Error<T, L> {
40 fn clone(&self) -> Self {
41 match self {
42 Error::ConnectError(e) => Error::ConnectError(Arc::clone(e)),
43 Error::ConnectTimeout => Error::ConnectTimeout,
44 Error::IncomingError(e) => Error::IncomingError(Arc::clone(e)),
45 Error::OutgoingError(e) => Error::OutgoingError(Arc::clone(e)),
46 Error::IRCParseError(e) => Error::IRCParseError(*e),
47 Error::LoginError(e) => Error::LoginError(Arc::clone(e)),
48 Error::ReconnectCmd => Error::ReconnectCmd,
49 Error::PingTimeout => Error::PingTimeout,
50 Error::RemoteUnexpectedlyClosedConnection => Error::RemoteUnexpectedlyClosedConnection,
51 }
52 }
53}