irc_command_micro/
error.rs

1use std::fmt;
2
3use crate::command::IRCCommand;
4
5#[derive(Debug, PartialEq)]
6pub enum MessageErrorDetails {
7    NoData,
8    NoPrefix,
9    NoClient,
10    FailedPrefixParse,
11    FailedCommandParse,
12    FailedParamParse,
13    NoCommand,
14    InvalidCommand,
15    NotEnoughParams,
16    BlankParams,
17    FailedBuild,
18    FailedSerialize,
19}
20
21impl MessageErrorDetails {
22    pub fn error_text(&self) -> &str {
23        match *self {
24            MessageErrorDetails::NoData => "No data in message",
25            MessageErrorDetails::NoClient => "No client identifier",
26            MessageErrorDetails::NoPrefix => "Missing : character",
27            MessageErrorDetails::FailedPrefixParse => "Failed to parse prefix data",
28            MessageErrorDetails::InvalidCommand => "Invalid command",
29            MessageErrorDetails::NoCommand => "No command provided",
30            MessageErrorDetails::FailedCommandParse => "Failed to parse command data",
31            MessageErrorDetails::FailedParamParse => "Failed to parse param data",
32            MessageErrorDetails::NotEnoughParams => "Not enough params for command",
33            MessageErrorDetails::FailedBuild => "Failed to build Message, unknown error",
34            MessageErrorDetails::FailedSerialize => "Failed to serialize message, unknown error",
35            MessageErrorDetails::BlankParams => "One or more params are blank",
36        }
37    }
38}
39
40#[derive(Debug, PartialEq)]
41pub struct MessageError {
42    pub command: Option<IRCCommand>,
43    pub detail: MessageErrorDetails,
44}
45
46impl fmt::Display for MessageError {
47    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48        write!(f, "MessageError {}", self.detail.error_text())
49    }
50}