aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src/error.rs
blob: 3e514fd4a3a67248390105c630b4d938ce50b37d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use serde::{Serialize, Deserialize};
use std::fmt::Display;
use serde::export::Formatter;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Serialize, Deserialize)]
pub enum Error {
    DisconnectedError,
    AlreadyConnectedError,
    InvalidChannelIdentifierError(String),
    InvalidServerAddrError(String, u16),
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::DisconnectedError => write!(f, "Not connected to a server"),
            Error::AlreadyConnectedError => write!(f, "Already connected to a server"),
            Error::InvalidChannelIdentifierError(id) => write!(f, "Couldn't find channel {}", id),
            Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}:{}", addr, port),
        }
    }
}