Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kareigu committed Jan 31, 2024
1 parent 2ac0662 commit 4af0559
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/commands/cmd/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ impl Command for Play {
let mut data = handle.typemap().write().await;
data.insert::<SongMetadataKey>(metadata.clone());
}
match handle.add_event(
Event::Track(TrackEvent::Error),
SongError {
ctx: ctx.clone(),
command: command.clone(),
},
) {
Ok(_) => (),
Err(e) => error!("Error adding SongError event: {}", e),
}
let embed_title = match handler.queue().len() == 1 {
true => "Playing",
false => "Added to queue",
Expand Down Expand Up @@ -270,6 +280,24 @@ impl EventHandler for SongStart {
}
}

struct SongError {
pub command: CommandInteraction,
pub ctx: Context,
}

#[async_trait]
impl EventHandler for SongError {
async fn act(&self, _ctx: &EventContext<'_>) -> Option<Event> {
match text_response(&self.ctx, &self.command, "Error playing song").await {
Ok(_) => None,
Err(e) => {
error!("Failed editing error response: {}", e);
None
}
}
}
}

async fn join_channel(
manager: Arc<Songbird>,
voip_data: VOIPData,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ pub async fn handle_commands(ctx: &Context, command: CommandInteraction) {
"{user} failed running command {cmd}",
user = user.tag(),
cmd = name
)
);
text_response(ctx, &command, "Error processing command")
.await
.unwrap_or(());
} else {
info!("{user} ran command {cmd}", user = user.tag(), cmd = name)
}
Expand Down

0 comments on commit 4af0559

Please sign in to comment.