diff options
| author | seth <[email protected]> | 2023-11-30 22:18:51 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2023-12-01 07:12:49 -0500 |
| commit | 76c0f94e6d7aa108424b34826eb7d8514b026287 (patch) | |
| tree | 7315bd6dfe52c158041bed64ba39781718a69335 /src/handlers/error.rs | |
| parent | db52e639b85d79bed870020aec7a045851ca5ee3 (diff) | |
feat: use eyre, better logging, & refactor
small commits be damned
Diffstat (limited to 'src/handlers/error.rs')
| -rw-r--r-- | src/handlers/error.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/handlers/error.rs b/src/handlers/error.rs new file mode 100644 index 0000000..b4e1361 --- /dev/null +++ b/src/handlers/error.rs @@ -0,0 +1,42 @@ +use crate::colors::Colors; +use crate::Data; + +use color_eyre::eyre::Report; +use log::*; +use poise::serenity_prelude::Timestamp; +use poise::FrameworkError; + +pub async fn handle(error: poise::FrameworkError<'_, Data, Report>) { + match error { + FrameworkError::Setup { error, .. } => error!("error setting up client! {error:#?}"), + + FrameworkError::Command { error, ctx } => { + error!("error in command {}:\n{error:?}", ctx.command().name); + ctx.send(|c| { + c.embed(|e| { + e.title("Something went wrong!") + .description("oopsie") + .timestamp(Timestamp::now()) + .color(Colors::Orange) + }) + }) + .await + .ok(); + } + + FrameworkError::EventHandler { + error, + ctx: _, + event: _, + framework: _, + } => { + error!("error while handling event:\n{error:#?}"); + } + + error => { + if let Err(e) = poise::builtins::on_error(error).await { + error!("error while handling an error: {}", e); + } + } + } +} |
