From cd2abf031507cfef108472da18d527331540ea97 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 23 Feb 2024 18:39:36 +0000 Subject: [PATCH] Add try/catch to command execution (#173) # Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Add try/catch around command execution to console log to stderr and reply in case a command breaks #67 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/173 Reviewed-by: VylpesTester Co-authored-by: Ethan Lane Co-committed-by: Ethan Lane --- src/client/interactionCreate/Button.ts | 8 +++++++- src/client/interactionCreate/ChatInputCommand.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/client/interactionCreate/Button.ts b/src/client/interactionCreate/Button.ts index fac2b78..6d6a926 100644 --- a/src/client/interactionCreate/Button.ts +++ b/src/client/interactionCreate/Button.ts @@ -12,6 +12,12 @@ export default class Button { return; } - item.Event.execute(interaction); + try { + item.Event.execute(interaction); + } catch (e) { + console.error(e); + + await interaction.reply("An error occurred while executing the event"); + } } } \ No newline at end of file diff --git a/src/client/interactionCreate/ChatInputCommand.ts b/src/client/interactionCreate/ChatInputCommand.ts index 3890744..784ce6e 100644 --- a/src/client/interactionCreate/ChatInputCommand.ts +++ b/src/client/interactionCreate/ChatInputCommand.ts @@ -22,6 +22,12 @@ export default class ChatInputCommand { itemToUse = itemForServer; } - itemToUse.Command.execute(interaction); + try { + itemToUse.Command.execute(interaction); + } catch (e) { + console.error(e); + + await interaction.reply("An error occurred while executing the command"); + } } } \ No newline at end of file