Skip to content

Commit eb371a5

Browse files
committed
override some framework errors for consistency
1 parent 235eab0 commit eb371a5

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/events/issue.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ async fn issue_embeds(data: &Data, message: &Message) -> Option<Vec<CreateEmbed>
107107
let client = octocrab::instance();
108108
let ratelimit = client.ratelimit();
109109

110-
let regex =
111-
Regex::new(r#" ?([a-zA-Z0-9-_.]+)?#([0-9]+) ?"#).expect("Expected numbers regex");
110+
let regex = Regex::new(r#" ?([a-zA-Z0-9-_.]+)?#([0-9]+) ?"#).expect("Expected numbers regex");
112111

113112
let custom_repos = { data.state.read().unwrap().issue_prefixes.clone() };
114113

src/main.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,38 @@ type Context<'a> = poise::Context<'a, Data, Error>;
2121
async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
2222
match error {
2323
poise::FrameworkError::Setup { error, .. } => panic!("Failed to start bot: {:?}", error),
24-
poise::FrameworkError::Command { error, ctx, .. } => {
25-
println!("Error in command `{}`: {:?}", ctx.command().name, error,);
24+
poise::FrameworkError::Command { ctx, error, .. } => {
25+
let error = error.to_string();
26+
eprintln!("An error occured in a command: {}", error);
27+
commands::respond_err(&ctx, "Command Error", &error).await;
2628
}
29+
30+
poise::FrameworkError::ArgumentParse {
31+
error, input, ctx, ..
32+
} => {
33+
let usage = match &ctx.command().help_text {
34+
Some(help_text) => &**help_text,
35+
None => "Please check the help menu for usage information",
36+
};
37+
let response = if let Some(input) = input {
38+
format!(
39+
"**Cannot parse `{}` as argument: {}**\n{}",
40+
input, error, usage
41+
)
42+
} else {
43+
format!("### {}\n{}", error, usage)
44+
};
45+
commands::respond_err(&ctx, "Argument Parsing Error", &response).await;
46+
}
47+
poise::FrameworkError::GuildOnly { ctx, .. } => {
48+
commands::respond_err(
49+
&ctx,
50+
"This command cannot be ran in DMs.",
51+
"You cannot run this command in DMs.",
52+
)
53+
.await;
54+
}
55+
2756
error => {
2857
if let Err(e) = poise::builtins::on_error(error).await {
2958
println!("Error while handling error: {}", e)

0 commit comments

Comments
 (0)