diff options
| author | Eskil Queseth <eskilq@kth.se> | 2020-10-17 21:17:46 +0200 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2020-10-17 21:17:46 +0200 |
| commit | 7675171e2c307c91a81b0daee915c2a114ae4612 (patch) | |
| tree | 34d3109424ae6f3798687da3710abf332d5814d5 /mumlib/src/error.rs | |
| parent | d66eea26a29ede1c8eb981d372011fb2e35dce14 (diff) | |
| parent | 39b13833187e4331fa32c1601f1bf1b1d6fa036a (diff) | |
| download | mum-7675171e2c307c91a81b0daee915c2a114ae4612.tar.gz | |
Merge remote-tracking branch 'origin/channel-name' into main
Diffstat (limited to 'mumlib/src/error.rs')
| -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 cb88aa7..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, - InvalidChannelIdError(u32), + 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::InvalidChannelIdError(id) => write!(f, "Invalid channel id: {}", 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 |
