irc_async/proto/
errors.rs

1use std::io;
2
3use tokio_util::codec::LinesCodecError;
4
5/// The main crate-wide error type.
6#[derive(Debug, Error)]
7pub enum IrcError {
8    /// An internal I/O error.
9    #[error("an io error occurred")]
10    Io(#[from] io::Error),
11
12    // /// An internal TLS error.
13    // #[error("a TLS error occurred")]
14    // Tls(#[source] TlsError),
15
16    // /// An internal synchronous channel closed.
17    // #[error("a sync channel closed")]
18    // SyncChannelClosed(#[source] RecvError),
19
20    // /// An internal asynchronous channel closed.
21    // #[error("an async channel closed")]
22    // AsyncChannelClosed(#[source] SendError<Message>),
23
24    // /// An internal oneshot channel closed.
25    // #[error("a oneshot channel closed")]
26    // OneShotCanceled(#[source] Canceled),
27
28    // /// An internal timer error.
29    // #[error("timer failed")]
30    // Timer(#[source] TimerError),
31
32    // /// Error for invalid configurations.
33    // #[error("invalid config: {}", path)]
34    // InvalidConfig {
35    //     /// The path to the configuration, or "<none>" if none specified.
36    //     path: String,
37    //     /// The detailed configuration error.
38    //     #[source]
39    //     cause: ConfigError,
40    // },
41    /// Error for invalid messages.
42    #[error("invalid message: {string}")]
43    InvalidMessage {
44        /// The string that failed to parse.
45        string: String,
46        /// The detailed message parsing error.
47        #[source]
48        cause: MessageParseError,
49    },
50    // /// Mutex for a logged transport was poisoned making the log inaccessible.
51    // #[error("mutex for a logged transport was poisoned")]
52    // PoisonedLog,
53
54    // /// Ping timed out due to no response.
55    // #[error("connection reset: no ping response")]
56    // PingTimeout,
57
58    // /// Failed to lookup an unknown codec.
59    // #[error("unknown codec: {}", codec)]
60    // UnknownCodec {
61    //     /// The attempted codec.
62    //     codec: String,
63    // },
64
65    // /// Failed to encode or decode something with the given codec.
66    // #[error("codec {} failed: {}", codec, data)]
67    // CodecFailed {
68    //     /// The canonical codec name.
69    //     codec: &'static str,
70    //     /// The data that failed to encode or decode.
71    //     data: String,
72    // },
73    /// Failed to encode or decode a line
74    #[error("line codec failed: {0}")]
75    Codec(#[from] LinesCodecError),
76    // /// All specified nicknames were in use or unusable.
77    // #[error("none of the specified nicknames were usable")]
78    // NoUsableNick,
79
80    // /// This allows you to produce any `failure::Error` within closures used by
81    // /// the irc crate. No errors of this kind will ever be produced by the crate
82    // /// itself.
83    // #[error("{}", inner)]
84    // Custom {
85    //     /// The actual error that occurred.
86    //     inner: failure::Error
87    // },
88}
89
90/// Errors that occur while parsing mode strings.
91#[derive(Debug, Error)]
92pub enum ModeParseError {
93    /// Invalid modifier used in a mode string (only + and - are valid).
94    #[error("invalid mode modifier: {modifier}")]
95    InvalidModeModifier {
96        /// The invalid mode modifier.
97        modifier: char,
98    },
99
100    /// Missing modifier used in a mode string.
101    #[error("missing mode modifier")]
102    MissingModeModifier,
103}
104
105/// Errors that occur when parsing messages.
106#[derive(Debug, Error)]
107pub enum MessageParseError {
108    /// The message was empty.
109    #[error("empty message")]
110    EmptyMessage,
111
112    /// The command was invalid (i.e. missing).
113    #[error("invalid command")]
114    InvalidCommand,
115
116    /// The mode string was malformed.
117    #[error("invalid mode string: {string}")]
118    InvalidModeString {
119        /// The invalid mode string.
120        string: String,
121        /// The detailed mode parsing error.
122        #[source]
123        cause: ModeParseError,
124    },
125
126    /// The subcommand used was invalid.
127    #[error("invalid {cmd} subcommand: {sub}")]
128    InvalidSubcommand {
129        /// The command whose invalid subcommand was referenced.
130        cmd: &'static str,
131        /// The invalid subcommand.
132        sub: String,
133    },
134}