diff options
| author | Eskil Queseth <eskilq@kth.se> | 2020-10-17 01:37:53 +0200 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2020-10-17 01:37:53 +0200 |
| commit | b1c1c227a0f5c171726f16f4f474536a718fd56f (patch) | |
| tree | ec451a84b76e59330be15e091861d436e41303d7 /mumlib | |
| parent | 9a9db2473928de240a38349b9726af9ae557374d (diff) | |
| download | mum-b1c1c227a0f5c171726f16f4f474536a718fd56f.tar.gz | |
add error checking if there are multiple valid channels to connect to
Diffstat (limited to 'mumlib')
| -rw-r--r-- | mumlib/src/error.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index 3e514fd..6c66c1f 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -8,17 +8,33 @@ pub type Result<T> = std::result::Result<T, Error>; pub enum Error { DisconnectedError, AlreadyConnectedError, - InvalidChannelIdentifierError(String), + ChannelIdentifierError(String, ChannelIdentifierError), 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), + Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), + Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + } + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub enum ChannelIdentifierError { + Invalid, + Ambiguous, +} + +impl Display for ChannelIdentifierError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + ChannelIdentifierError::Invalid => write!(f, "Invalid channel identifier"), + ChannelIdentifierError::Ambiguous => write!(f, "Ambiguous channel identifier"), } } }
\ No newline at end of file |
