diff options
| author | Max Audron <audron@cocaine.farm> | 2021-10-10 16:11:00 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2021-10-10 16:11:00 +0200 |
| commit | a1f36810f47cb16bcd308665a68f4899b1d00ef1 (patch) | |
| tree | 686c9c13122703eebd728e816bc4b67b0d99fba0 /src/hooks/sed.rs | |
| parent | set correct path for rust ci template (diff) | |
fix and improve hook error handling
Diffstat (limited to 'src/hooks/sed.rs')
| -rw-r--r-- | src/hooks/sed.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/hooks/sed.rs b/src/hooks/sed.rs index 1ee0b20..6d6583c 100644 --- a/src/hooks/sed.rs +++ b/src/hooks/sed.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use irc::client::prelude::*; use sedregex::ReplaceCommand; @@ -16,11 +16,8 @@ impl Sed { Sed(HashMap::new()) } - pub fn log(&mut self, _bot: &crate::Bot, msg: Message) { - match self.log_msg(msg) { - Ok(_) => (), - Err(err) => tracing::error!("failed to log new message: {:?}", err), - } + pub fn log(&mut self, _bot: &crate::Bot, msg: Message) -> Result<()> { + self.log_msg(msg).context("failed to log new message") } fn log_msg(&mut self, msg: Message) -> Result<()> { @@ -46,17 +43,17 @@ impl Sed { Ok(()) } - pub fn replace(&mut self, bot: &crate::Bot, msg: Message) { + pub fn replace(&mut self, bot: &crate::Bot, msg: Message) -> Result<()> { match self.find_and_replace(&msg) { Ok(res) => match bot.send_privmsg(msg.response_target().unwrap(), res.as_str()) { - Ok(_) => (), - Err(_) => tracing::error!( + Ok(_) => Ok(()), + Err(_) => bail!( "failed to send message: \"{:?}\" to channel: {:?}", msg.response_target().unwrap(), res ), }, - Err(_) => tracing::debug!("did not find match for: {:?}", msg), + Err(_) => bail!("did not find match for: {:?}", msg), } } |
