Improve error handling: prevent silent failures and double-reply crashes#3
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
Improve error handling: prevent silent failures and double-reply crashes#3devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
- Add utils/safeReply.js with safeReply/safeErrorReply helpers that check replied/deferred state before responding, preventing unhandled DiscordAPIError[InteractionAlreadyReplied] crashes - Wrap all catch blocks across admin, moderation, utility, and fun commands with safeErrorReply instead of raw interaction.reply - Add try/catch to commands missing error handling: report, userinfo, serverinfo, Good, ping, roll - Fix coinflip setTimeout callback: errors inside async setTimeout were silently swallowed as unhandled rejections - Fix avatar collector handlers: select menu errors now caught, collector cleanup logs failures instead of silently swallowing - Fix interactionCreate event: button handler wrapped in try/catch, unknown interactions logged instead of silently ignored - Fix deploy-commands.js: add per-category/file error handling so one broken command file does not crash the entire deployment; also fix pre-existing syntax error (missing closing brace) - Add Express server error handler for port-in-use failures - Add process-level unhandledRejection and uncaughtException handlers - Log stack traces consistently (error.stack || error.message) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The bot had many code paths where errors were silently swallowed or could crash the process:
Double-reply crashes — Every
catchblock calledinteraction.reply()directly. If the command had already replied (partial success), this throwsDiscordAPIError[InteractionAlreadyReplied]which was unhandled. Fixed by introducingutils/safeReply.jswithsafeReply/safeErrorReplyhelpers that checkinteraction.replied/interaction.deferredand fall back tofollowUp, with a last-resort console log if even that fails. All catch blocks across all commands now use this.Missing try/catch — Six commands had zero error handling:
report,userinfo,serverinfo,Good,ping,roll. Any thrown error would propagate as an unhandled rejection. Each now has a try/catch that logs the stack and replies with an error embed.Silent swallowing —
coinflip'ssetTimeoutasync callback had no catch (unhandled rejection ifeditReplyfails).avatar's collectorendhandler used.catch(() => {}).interactionCreate's button handler had no try/catch, and unknown interaction types hit emptyelse {}blocks with no logging. All now log errors and/or handle failures explicitly.Process-level safety net — Added
process.on('unhandledRejection')andprocess.on('uncaughtException')handlers inindex.js, plus an error listener on Expressapp.listen()for port conflicts.Pre-existing syntax bug —
deploy-commands.jshad a missing closing brace (};instead of} };), plus no per-file error handling in the inner loop (one broken command file would crash the entire deploy). Both fixed.Link to Devin session: https://app.devin.ai/sessions/79a90cea8b934456b1dcee88a1f1d40b
Requested by: @AliCloud0