Expand description
An opinionated plug-and-play library for error handling in Discord bots made
with poise.
To get started, see on_error.
§Examples
Goober Bot is a Discord bot which uses poise_error, here’s how it looks:
use poise::{ChoiceParameter, command};
use poise_error::{
UserError,
anyhow::{self, anyhow, bail},
};
#[derive(ChoiceParameter)]
enum ErrorKind {
User,
Internal,
Panic,
}
/// Fails intentionally
#[command(slash_command)]
async fn error(
_ctx: poise_error::Context<'_>,
#[description = "Kind of error to return"] kind: ErrorKind,
) -> anyhow::Result<()> {
match kind {
ErrorKind::User => bail!(UserError(
anyhow!("This is an example of a user error")
.context("This is an example of extra context")
)),
ErrorKind::Internal => Err(anyhow!("This is an example of an internal error")
.context("This is an example of extra context")),
ErrorKind::Panic => panic!("This is an example of a panic"),
}
}Re-exports§
pub use anyhow;
Structs§
- User
Error - An anticipated error made by a user.
Functions§
- dedup_
error_ chain - Removes duplicates from an error’s chain.
- on_
error - Plug this into your
poise::FrameworkOptionsto letpoise_errorhandle your bot’s errors. - try_
handle_ error - Handles errors given by
poise.
Type Aliases§
- Context
- A shorthand for the
poise::Contextenum.