{"record":{"id":"e9a767ec52f55f2f","repo":"RocketChat/Rocket.Chat","slug":"invalid-message-id-e9a767","errorCode":null,"errorMessage":"Invalid message id","messagePattern":"Invalid message id","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/app/apps/server/bridges/moderation.ts","lineNumber":18,"sourceCode":"import type { IAppServerOrchestrator } from '@rocket.chat/apps';\nimport { ModerationBridge } from '@rocket.chat/apps/dist/server/bridges/ModerationBridge';\nimport type { IMessage } from '@rocket.chat/apps-engine/definition/messages';\nimport type { IUser } from '@rocket.chat/apps-engine/definition/users';\nimport { ModerationReports } from '@rocket.chat/models';\n\nimport { reportMessage } from '../../../../server/lib/moderation/reportMessage';\n\nexport class AppModerationBridge extends ModerationBridge {\n\tconstructor(private readonly orch: IAppServerOrchestrator) {\n\t\tsuper();\n\t}\n\n\tprotected async report(messageId: IMessage['id'], description: string, userId: string, appId: string): Promise<void> {\n\t\tthis.orch.debugLog(`The App ${appId} is creating a new report.`);\n\n\t\tif (!messageId) {\n\t\t\tthrow new Error('Invalid message id');\n\t\t}\n\n\t\tif (!description) {\n\t\t\tthrow new Error('Invalid description');\n\t\t}\n\n\t\tawait reportMessage(messageId, description, userId || 'rocket.cat');\n\t}\n\n\tprotected async dismissReportsByMessageId(messageId: IMessage['id'], reason: string, action: string, appId: string): Promise<void> {\n\t\tthis.orch.debugLog(`The App ${appId} is dismissing reports by message id.`);\n\n\t\tif (!messageId) {\n\t\t\tthrow new Error('Invalid message id');\n\t\t}\n\n\t\tawait ModerationReports.hideMessageReportsByMessageId(messageId, appId, reason, action);\n\t}","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/app/apps/server/bridges/moderation.ts#L1-L36","documentation":"Thrown by AppModerationBridge.report when the messageId argument is falsy. The bridge is the Apps Engine entry point for message reporting; it forwards to server/lib/moderation/reportMessage, which itself re-validates and will throw 'error-invalid-message_id' if the id does not correspond to an existing message. This particular throw is the cheap pre-check that prevents a needless DB round-trip.","triggerScenarios":"An App calls the moderation accessor's report endpoint with messageId set to undefined, null, '' or 0 — typically because the App held a message object whose id field was never populated (e.g. a message constructed locally but not yet persisted) or a value extracted from an event payload that was missing the id property.","commonSituations":"Calling report on a message stub built for sending before the send completed; deserializing a cached message that lost its id; chaining report after a send whose return value (the id) was not awaited; UI actions that pass an empty selection.","solutions":["Ensure messageId is the persisted message's id — await the send and use the returned id before reporting.","Guard the call: `if (!messageId) return;` or surface a user-facing error instead of letting the bridge throw.","When handling events, read message.id defensively and skip when absent."],"exampleFix":"// before\nawait moderation.report('', 'spam', userId, appId);\n\n// after\nif (message.id) {\n  await moderation.report(message.id, 'spam', userId, appId);\n}","handlingStrategy":"validation","validationCode":"if (!messageId || typeof messageId !== 'string') {\n  throw new Error('A valid message id is required to report');\n}\nawait moderation.report(messageId, description, userId, appId);","typeGuard":"function isMessageId(value: unknown): value is string {\n  return typeof value === 'string' && value.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always await the send that produces the message id before wiring a report action to it.","Read message.id defensively from event payloads and skip the action when absent.","Validate required ids at the App's action-handler boundary, not deep in the call chain."],"tags":["apps-engine","moderation-bridge","validation","message-id","truthy-check"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}