Skip to content

Commit f613852

Browse files
JohnMcLearclaude
andcommitted
appendChatMessage: throw explicit error instead of getPadSafe (review)
Per review: replace the getPadSafe(padID, true) existence check with an explicit `throw new CustomError('padID does not exist', 'apierror')` so chat messages can't create pads, without fetching the pad. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b3c2ffb commit f613852

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/node/db/API.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,13 @@ exports.appendChatMessage = async (padID: string, text: string|object, authorID:
414414
time = Date.now();
415415
}
416416

417-
// Require the pad to already exist, like the other content API methods.
418-
// Without this, sendChatMessageToPadClients -> padManager.getPad() would
419-
// create the pad on demand with default content, so the documented
420-
// {code:1,"padID does not exist"} result would never be returned.
421-
await getPadSafe(padID, true);
417+
// Reject messages addressed to a pad that doesn't exist. Without this check
418+
// the downstream padManager.getPad() would create the pad on demand with
419+
// default content, so the documented {code:1,"padID does not exist"} result
420+
// would never be returned.
421+
if (!await padManager.doesPadExists(padID)) {
422+
throw new CustomError('padID does not exist', 'apierror');
423+
}
422424

423425
// save chat message to database and send message to all connected clients
424426
await padMessageHandler.sendChatMessageToPadClients(new ChatMessage(text, authorID, time), padID);

0 commit comments

Comments
 (0)