twitch_irc/
error.rs

1use crate::login::LoginCredentials;
2use crate::message::IRCParseError;
3use crate::transport::Transport;
4use std::sync::Arc;
5use thiserror::Error;
6
7/// Errors that can occur while trying to execute some action on a `TwitchIRCClient`.
8#[derive(Error, Debug)]
9pub enum Error<T: Transport, L: LoginCredentials> {
10    /// Underlying transport failed to connect
11    #[error("Underlying transport failed to connect: {0}")]
12    ConnectError(Arc<T::ConnectError>),
13    /// Underlying transport failed to connect in time
14    #[error("Underlying transport failed to connect: Connect timed out")]
15    ConnectTimeout,
16    /// Error received from incoming stream of messages
17    #[error("Error received from incoming stream of messages: {0}")]
18    IncomingError(Arc<T::IncomingError>),
19    /// Error received while trying to send message(s) out
20    #[error("Error received while trying to send message(s) out: {0}")]
21    OutgoingError(Arc<T::OutgoingError>),
22    /// Incoming message was not valid IRC
23    #[error("Incoming message was not valid IRC: {0}")]
24    IRCParseError(IRCParseError),
25    /// Failed to get login credentials to log in with
26    #[error("Failed to get login credentials to log in with: {0}")]
27    LoginError(Arc<L::Error>),
28    /// Received RECONNECT command by IRC server
29    #[error("Received RECONNECT command by IRC server")]
30    ReconnectCmd,
31    /// Did not receive a PONG back after sending PING
32    #[error("Did not receive a PONG back after sending PING")]
33    PingTimeout,
34    /// Remote server unexpectedly closed connection
35    #[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}