Skip to content

Improve error handling: prevent silent failures and double-reply crashes#3

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1780360597-improve-error-handling
Open

Improve error handling: prevent silent failures and double-reply crashes#3
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1780360597-improve-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

The bot had many code paths where errors were silently swallowed or could crash the process:

Double-reply crashes — Every catch block called interaction.reply() directly. If the command had already replied (partial success), this throws DiscordAPIError[InteractionAlreadyReplied] which was unhandled. Fixed by introducing utils/safeReply.js with safeReply/safeErrorReply helpers that check interaction.replied/interaction.deferred and fall back to followUp, 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 swallowingcoinflip's setTimeout async callback had no catch (unhandled rejection if editReply fails). avatar's collector end handler used .catch(() => {}). interactionCreate's button handler had no try/catch, and unknown interaction types hit empty else {} blocks with no logging. All now log errors and/or handle failures explicitly.

Process-level safety net — Added process.on('unhandledRejection') and process.on('uncaughtException') handlers in index.js, plus an error listener on Express app.listen() for port conflicts.

Pre-existing syntax bugdeploy-commands.js had 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

- 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>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant