Merge pull request #117 from pinkisemils/feature-no-panic-on-nick-conflict

An error for when there are no valid nicks.
This commit is contained in:
Aaron Weiss 2018-02-12 20:26:20 +01:00 committed by GitHub
commit c13c4294b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -398,7 +398,7 @@ impl ClientState {
let alt_nicks = self.config().alternate_nicknames(); let alt_nicks = self.config().alternate_nicknames();
let mut index = self.alt_nick_index.write().unwrap(); let mut index = self.alt_nick_index.write().unwrap();
if *index >= alt_nicks.len() { if *index >= alt_nicks.len() {
panic!("All specified nicknames were in use or disallowed.") return Err(error::IrcError::NoUsableNick);
} else { } else {
self.send(NICK(alt_nicks[*index].to_owned()))?; self.send(NICK(alt_nicks[*index].to_owned()))?;
*index += 1; *index += 1;
@ -1044,7 +1044,6 @@ mod test {
} }
#[test] #[test]
#[should_panic(expected = "All specified nicknames were in use or disallowed.")]
fn ran_out_of_nicknames() { fn ran_out_of_nicknames() {
let value = ":irc.pdgn.co 433 * test :Nickname is already in use.\r\n\ let value = ":irc.pdgn.co 433 * test :Nickname is already in use.\r\n\
:irc.pdgn.co 433 * test2 :Nickname is already in use.\r\n"; :irc.pdgn.co 433 * test2 :Nickname is already in use.\r\n";
@ -1052,9 +1051,15 @@ mod test {
mock_initial_value: Some(value.to_owned()), mock_initial_value: Some(value.to_owned()),
..test_config() ..test_config()
}).unwrap(); }).unwrap();
client.for_each_incoming(|message| { let res = client.for_each_incoming(|message| {
println!("{:?}", message); println!("{:?}", message);
}).unwrap(); });
use error::IrcError;
match res.expect_err("returned no error when no valid nicks were specified") {
IrcError::NoUsableNick => (),
_ => panic!("expected {} error when no valid nicks are specified"),
}
} }
#[test] #[test]

View file

@ -91,6 +91,10 @@ pub enum IrcError {
/// The data that failed to encode or decode. /// The data that failed to encode or decode.
data: String, data: String,
}, },
/// All specified nicks were in use or unusable.
#[fail(display = "no usable nicks")]
NoUsableNick
} }
/// Errors that occur when parsing messages. /// Errors that occur when parsing messages.