Debian Codegraph @

src/error.rs

raw symbols SCIP
1 //! IRC protocol errors using `failure`.
2
3 use thiserror::Error;
4
5 /// A `Result` type for IRC `ProtocolErrors`.
6 pub type Result<T, E = ProtocolError> = ::std::result::Result<T, E>;
7
8 /// An IRC protocol error.
9 #[derive(Debug, Error)]
10 pub enum ProtocolError {
11 /// An internal I/O error.
12 #[error("an io error occurred")]
13 Io(#[source] std::io::Error),
14
15 /// Error for invalid messages.
16 #[error("invalid message: {}", string)]
17 InvalidMessage {
18 /// The string that failed to parse.
19 string: String,
20 /// The detailed message parsing error.
21 #[source]
22 cause: MessageParseError,
23 },
24 }
25
26 impl From<std::io::Error> for ProtocolError {
27 fn from(e: std::io::Error) -> ProtocolError {
28 ProtocolError::Io(e)
29 }
30 }
31
32 /// Errors that occur when parsing messages.
33 #[derive(Debug, Error)]
34 pub enum MessageParseError {
35 /// The message was empty.
36 #[error("empty message")]
37 EmptyMessage,
38
39 /// The command was invalid (i.e. missing).
40 #[error("invalid command")]
41 InvalidCommand,
42
43 /// The mode string was malformed.
44 #[error("invalid mode string: {}", string)]
45 InvalidModeString {
46 /// The invalid mode string.
47 string: String,
48 /// The detailed mode parsing error.
49 #[source]
50 cause: ModeParseError,
51 },
52
53 /// The subcommand used was invalid.
54 #[error("invalid {} subcommand: {}", cmd, sub)]
55 InvalidSubcommand {
56 /// The command whose invalid subcommand was referenced.
57 cmd: &'static str,
58 /// The invalid subcommand.
59 sub: String,
60 },
61 }
62
63 /// Errors that occur while parsing mode strings.
64 #[derive(Debug, Error)]
65 pub enum ModeParseError {
66 /// Invalid modifier used in a mode string (only + and - are valid).
67 #[error("invalid mode modifier: {}", modifier)]
68 InvalidModeModifier {
69 /// The invalid mode modifier.
70 modifier: char,
71 },
72
73 /// Missing modifier used in a mode string.
74 #[error("missing mode modifier")]
75 MissingModeModifier,
76 }