diff options
| author | Eskil <eskilq@kth.se> | 2020-10-16 02:36:13 +0200 |
|---|---|---|
| committer | Eskil <eskilq@kth.se> | 2020-10-16 02:36:13 +0200 |
| commit | 27d8b16b40a5f5a0633c2e54640999d4e6cdd9a3 (patch) | |
| tree | 769971b8921aa2c0d5c2845323a898f1603cfebe /mumlib/src | |
| parent | 18a3c0b3cf8254b70857e31ddd2b6213b10db156 (diff) | |
| parent | d15a4adb457b8caab4e76baff8e27ade347a275d (diff) | |
| download | mum-27d8b16b40a5f5a0633c2e54640999d4e6cdd9a3.tar.gz | |
Merge branch 'error-handling' into 'main'
Error handling
Closes #13
See merge request gustav/mum!3
Diffstat (limited to 'mumlib/src')
| -rw-r--r-- | mumlib/src/error.rs | 24 | ||||
| -rw-r--r-- | mumlib/src/lib.rs | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs new file mode 100644 index 0000000..cb88aa7 --- /dev/null +++ b/mumlib/src/error.rs @@ -0,0 +1,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, + 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 diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs index ebf2019..b77653c 100644 --- a/mumlib/src/lib.rs +++ b/mumlib/src/lib.rs @@ -1,5 +1,6 @@ pub mod command; pub mod state; +pub mod error; use colored::*; use log::*; |
