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 /mumd | |
| parent | 9a9db2473928de240a38349b9726af9ae557374d (diff) | |
| download | mum-b1c1c227a0f5c171726f16f4f474536a718fd56f.tar.gz | |
add error checking if there are multiple valid channels to connect to
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/src/state.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/mumd/src/state.rs b/mumd/src/state.rs index d3f9a8e..623cfba 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -9,7 +9,7 @@ use mumlib::command::{Command, CommandResponse}; use mumlib::state::Server; use std::net::ToSocketAddrs; use tokio::sync::{mpsc, watch}; -use mumlib::error::Error; +use mumlib::error::{Error, ChannelIdentifierError}; #[derive(Clone, Debug, Eq, PartialEq)] pub enum StatePhase { @@ -61,12 +61,15 @@ impl State { let channels = self.server() .unwrap() .channels(); - let mut idents = channels.iter() - .map(|e| (e.0, e.1.path(channels))); - let id = match idents.find(|e| e.1.ends_with(&channel_identifier)) { - Some(v) => *v.0, - None => return (false, Err(Error::InvalidChannelIdentifierError(channel_identifier))), + let matches = channels.iter() + .map(|e| (e.0, e.1.path(channels))) + .filter(|e| e.1.ends_with(&channel_identifier)) + .collect::<Vec<_>>(); + let id = match matches.len() { + 0 => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Invalid))), + 1 => *matches.get(0).unwrap().0, + _ => return (false, Err(Error::ChannelIdentifierError(channel_identifier, ChannelIdentifierError::Ambiguous))), }; let mut msg = msgs::UserState::new(); |
