aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/emoji.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-02 22:11:21 +0100
committerJokler <jokler.contact@gmail.com>2018-03-02 22:11:21 +0100
commit0b4131e8cf91ed10f24d3faed341034d518aea53 (patch)
tree09498ec2f2ec495a1b45a6762e61ed67f496c6f8 /src/plugins/emoji.rs
parent0bcc7c0923852b48ebbb94ceeecc98f551fa920d (diff)
downloadfrippy-0b4131e8cf91ed10f24d3faed341034d518aea53.tar.gz
frippy-0b4131e8cf91ed10f24d3faed341034d518aea53.zip
Use Error & ErrorKind pair instead of simple enums
Each plugin should define its own errors with a respective variant in the main ErrorKind of frippy. A new procedural macro was added to reduce the boilerplate required for new error system. It can be used by deriving "Error" and adding a name for the Error via the "error" attribute. So far non of the plugins except for Url and Factoids use their own errors yet.
Diffstat (limited to 'src/plugins/emoji.rs')
-rw-r--r--src/plugins/emoji.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/plugins/emoji.rs b/src/plugins/emoji.rs
index a4276f4..f1d9376 100644
--- a/src/plugins/emoji.rs
+++ b/src/plugins/emoji.rs
@@ -3,10 +3,14 @@ extern crate unicode_names;
use std::fmt;
use irc::client::prelude::*;
-use irc::error::IrcError;
use plugin::*;
+use error::FrippyError;
+use error::ErrorKind as FrippyErrorKind;
+use failure::Fail;
+use failure::ResultExt;
+
struct EmojiHandle {
symbol: char,
count: i32,
@@ -100,21 +104,23 @@ impl Plugin for Emoji {
.send_privmsg(message.response_target().unwrap(), &self.emoji(content))
{
Ok(_) => ExecutionStatus::Done,
- Err(e) => ExecutionStatus::Err(Box::new(e)),
+ Err(e) => ExecutionStatus::Err(e.context(FrippyErrorKind::Connection).into()),
},
_ => ExecutionStatus::Done,
}
}
- fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), IrcError> {
+ fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), FrippyError> {
panic!("Emoji should not use threading")
}
- fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), IrcError> {
- client.send_notice(
- &command.source,
- "This Plugin does not implement any commands.",
- )
+ fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), FrippyError> {
+ Ok(client
+ .send_notice(
+ &command.source,
+ "This Plugin does not implement any commands.",
+ )
+ .context(FrippyErrorKind::Connection)?)
}
fn evaluate(&self, _: &IrcClient, command: PluginCommand) -> Result<String, String> {
@@ -126,6 +132,3 @@ impl Plugin for Emoji {
}
}
}
-
-#[cfg(test)]
-mod tests {}