aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2020-10-16 02:18:59 +0200
committerEskil Queseth <eskilq@kth.se>2020-10-16 02:18:59 +0200
commit6a6ee0c9db9de7f7632050ad4984a3f92d8a96e9 (patch)
tree61d83227f083c98770677f9cd1a1ea787b2438e4
parent6136a8d7e9d251348fa514f04d74aa19257c1e18 (diff)
downloadmum-6a6ee0c9db9de7f7632050ad4984a3f92d8a96e9.tar.gz
add pretty printing for error type
-rw-r--r--mumd/src/state.rs4
-rw-r--r--mumlib/src/error.rs17
2 files changed, 17 insertions, 4 deletions
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index a9dbfc6..82d671e 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -59,7 +59,7 @@ impl State {
}
if let Some(server) = &self.server {
if !server.channels().contains_key(&channel_id) {
- return (false, Err(Error::InvalidChannelIdError));
+ return (false, Err(Error::InvalidChannelIdError(channel_id)));
}
}
let mut msg = msgs::UserState::new();
@@ -97,7 +97,7 @@ impl State {
Ok(Some(v)) => v,
_ => {
warn!("Error parsing server addr");
- return (false, Err(Error::InvalidServerAddrError));
+ return (false, Err(Error::InvalidServerAddrError(host, port)));
}
};
self.connection_info_sender
diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs
index 20415b0..cb88aa7 100644
--- a/mumlib/src/error.rs
+++ b/mumlib/src/error.rs
@@ -1,4 +1,6 @@
use serde::{Serialize, Deserialize};
+use std::fmt::Display;
+use serde::export::Formatter;
pub type Result<T> = std::result::Result<T, Error>;
@@ -6,6 +8,17 @@ pub type Result<T> = std::result::Result<T, Error>;
pub enum Error {
DisconnectedError,
AlreadyConnectedError,
- InvalidChannelIdError,
- InvalidServerAddrError,
+ InvalidChannelIdError(u32),
+ 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),
+ }
+ }
} \ No newline at end of file