From 3463a9349bce8e06d79a9b70926395279c00705f Mon Sep 17 00:00:00 2001 From: xpoes123 Date: Mon, 29 Jun 2026 23:33:31 -0400 Subject: [PATCH] fix: guard adjustQuery against unhandled promise rejections Co-Authored-By: Claude Opus 4.8 (1M context) --- quizbowl/QuestionRoom.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/quizbowl/QuestionRoom.js b/quizbowl/QuestionRoom.js index af3363b68..4b374e864 100644 --- a/quizbowl/QuestionRoom.js +++ b/quizbowl/QuestionRoom.js @@ -111,18 +111,25 @@ export default class QuestionRoom extends Room { if (doNotFetch) { return; } - switch (this.mode) { - case MODE_ENUM.SET_NAME: - this.packet = await this.getPacket({ setName: this.query.setName, packetNumber: this.query.packetNumbers[0] }); - break; - case MODE_ENUM.RANDOM: - for (const s of this.supportedQuestionTypes) { - const query = { ...this.query, number: 1 }; - this.randomQuestionCache[s] = this.categoryManager.percentView - ? [] - : await this.getRandomQuestions(s, query); - } - break; + try { + switch (this.mode) { + case MODE_ENUM.SET_NAME: + this.packet = await this.getPacket({ setName: this.query.setName, packetNumber: this.query.packetNumbers[0] }); + break; + case MODE_ENUM.RANDOM: + for (const s of this.supportedQuestionTypes) { + const query = { ...this.query, number: 1 }; + this.randomQuestionCache[s] = this.categoryManager.percentView + ? [] + : await this.getRandomQuestions(s, query); + } + break; + } + } catch (error) { + // adjustQuery is invoked fire-and-forget from message handlers, so a + // rejected DB call here would become an unhandled rejection and crash + // the process. Log and bail; the next getNextQuestion will refetch. + console.error(`adjustQuery failed to fetch questions in room ${this.name}:`, error); } }