Skip to content

fix: catch adjustQuery errors to prevent unhandled rejection crash#530

Open
xpoes123 wants to merge 1 commit into
qbreader:mainfrom
xpoes123:fix/adjustquery-unhandled-rejection
Open

fix: catch adjustQuery errors to prevent unhandled rejection crash#530
xpoes123 wants to merge 1 commit into
qbreader:mainfrom
xpoes123:fix/adjustquery-unhandled-rejection

Conversation

@xpoes123

@xpoes123 xpoes123 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

adjustQuery in quizbowl/QuestionRoom.js awaits database calls (getPacket, getRandomQuestions) but is invoked fire-and-forget from synchronous message handlers with no await or .catch. A transient DB error produces an unhandled promise rejection, which terminates the Node process on Node 15+.

Problem

Every call site invokes adjustQuery without catching its return value:

// e.g. in a message handler
this.adjustQuery(...);  // no await, no .catch

If getPacket or getRandomQuestions throws — for instance during a brief MongoDB hiccup — the rejection escapes adjustQuery with no handler. Node 15+ converts unhandled rejections to fatal crashes, taking down all active rooms.

Changes

  • Wraps the switch block inside adjustQuery in a try/catch.
  • On error, logs via console.error (including the room name) and returns early.
  • The query fields (this.query) are still updated before the fetch, so the next getNextQuestion call will refetch correctly.

Risk & testing

The happy path is unchanged. The change is conservative: it contains the failure at a single point rather than requiring a .catch at every call site. semistandard and node --check pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@xpoes123 xpoes123 changed the title fix: prevent unhandled rejection from adjustQuery crashing the process fix: catch adjustQuery errors to prevent unhandled rejection crash Jun 30, 2026
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