aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/currency.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/currency.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/currency.rs')
-rw-r--r--src/plugins/currency.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/plugins/currency.rs b/src/plugins/currency.rs
index 958c8e2..53a245c 100644
--- a/src/plugins/currency.rs
+++ b/src/plugins/currency.rs
@@ -6,7 +6,6 @@ use std::io::Read;
use std::num::ParseFloatError;
use irc::client::prelude::*;
-use irc::error::IrcError;
use self::reqwest::Client;
use self::reqwest::header::Connection;
@@ -14,6 +13,10 @@ use self::serde_json::Value;
use plugin::*;
+use error::FrippyError;
+use error::ErrorKind as FrippyErrorKind;
+use failure::ResultExt;
+
#[derive(PluginName, Default, Debug)]
pub struct Currency;
@@ -124,20 +127,28 @@ impl Plugin for Currency {
ExecutionStatus::Done
}
- fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), IrcError> {
+ fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), FrippyError> {
panic!("Currency does not implement the execute function!")
}
- fn command(&self, client: &IrcClient, mut command: PluginCommand) -> Result<(), IrcError> {
+ fn command(&self, client: &IrcClient, mut command: PluginCommand) -> Result<(), FrippyError> {
if command.tokens.is_empty() {
- return client.send_notice(&command.source, &self.invalid_command(client));
+ return Ok(client
+ .send_notice(&command.source, &self.invalid_command(client))
+ .context(FrippyErrorKind::Connection)?);
}
match command.tokens[0].as_ref() {
- "help" => client.send_notice(&command.source, &self.help(client)),
+ "help" => Ok(client
+ .send_notice(&command.source, &self.help(client))
+ .context(FrippyErrorKind::Connection)?),
_ => match self.convert(client, &mut command) {
- Ok(msg) => client.send_privmsg(&command.target, &msg),
- Err(msg) => client.send_notice(&command.source, &msg),
+ Ok(msg) => Ok(client
+ .send_privmsg(&command.target, &msg)
+ .context(FrippyErrorKind::Connection)?),
+ Err(msg) => Ok(client
+ .send_notice(&command.source, &msg)
+ .context(FrippyErrorKind::Connection)?),
},
}
}
@@ -153,6 +164,3 @@ impl Plugin for Currency {
}
}
}
-
-#[cfg(test)]
-mod tests {}