{"record":{"id":"dbc29bb2d4ad1762","repo":"RocketChat/Rocket.Chat","slug":"invalid-message-id","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/messages.ts","lineNumber":62,"sourceCode":"\t\t\tthrow new Error('Invalid editor assigned to the message for the update.');\n\t\t}\n\n\t\t// #TODO: #AppsEngineTypes - Remove explicit types and typecasts once the apps-engine definition/implementation mismatch is fixed.\n\t\tconst msg = await this.orch.getConverters()?.get('messages').convertAppMessage(message, true);\n\t\tconst editor = await Users.findOneById(message.editor.id);\n\n\t\tif (!editor) {\n\t\t\tthrow new Error('Invalid editor assigned to the message for the update.');\n\t\t}\n\n\t\tawait updateMessage(msg as IMessage, editor);\n\t}\n\n\tprotected async delete(message: IAppsMessage, user: IAppsUser, appId: string): Promise<void> {\n\t\tthis.orch.debugLog(`The App ${appId} is deleting a message.`);\n\n\t\tif (!message.id) {\n\t\t\tthrow new Error('Invalid message id');\n\t\t}\n\n\t\tconst convertedMsg = await this.orch.getConverters()?.get('messages').convertAppMessage(message);\n\t\tconst convertedUser = (await Users.findOneById(user.id)) || this.orch.getConverters()?.get('users').convertToRocketChat(user);\n\n\t\tawait deleteMessage(convertedMsg as IMessage, convertedUser);\n\t}\n\n\tprotected async notifyUser(user: IAppsUser, message: IAppsMessage, appId: string): Promise<void> {\n\t\tthis.orch.debugLog(`The App ${appId} is notifying a user.`);\n\n\t\tconst msg = await this.orch.getConverters()?.get('messages').convertAppMessage(message);\n\n\t\tif (!msg) {\n\t\t\treturn;\n\t\t}\n\n\t\tvoid api.broadcast('notify.ephemeralMessage', user.id, msg.rid, {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/app/apps/server/bridges/messages.ts#L44-L80","documentation":"Thrown by AppMessageBridge.delete when message.id is falsy. Deletion requires the target message id; without it the bridge cannot call deleteMessage, so it rejects the call immediately. It guards against undefined/id-less message objects reaching the delete path.","triggerScenarios":"An App calls the message modifier's delete (e.g. app.getModify().deleteMessage(message)) with a message whose id is undefined, null, or empty string.","commonSituations":"App builds a partial message object for deletion and forgets id; App forwards a message that lost id through serialization; App confuses a constructed message (pre-send, no id) with a stored one; refactoring dropped the id field.","solutions":["Ensure message.id is set to an existing message _id before calling deleteMessage.","Fetch the message first via the read accessor and operate on the returned object.","Add an assertion (if (!message.id) throw) in the App with a descriptive message.","Distinguish delete-by-id from delete-by-object at the call site."],"exampleFix":"// before\nawait app.getModify().deleteMessage({ msg: 'to delete' });\n\n// after\nif (!message.id) {\n  throw new Error('Cannot delete a message without an id');\n}\nawait app.getModify().deleteMessage(message);","handlingStrategy":"validation","validationCode":"function assertMessageId(message: IAppsMessage): asserts message is IAppsMessage & { id: string } {\n  if (!message.id) {\n    throw new Error('Cannot delete message: message.id is required');\n  }\n}\nassertMessageId(message);\nawait app.getModify().deleteMessage(message);","typeGuard":"const hasMessageId = (m: IAppsMessage): m is IAppsMessage & { id: string } =>\n  typeof m.id === 'string' && m.id.length > 0;","tryCatchPattern":"try {\n  await app.getModify().deleteMessage(message);\n} catch (e) {\n  if ((e as Error).message === 'Invalid message id') {\n    // fetch the stored message and operate on its id\n  }\n  throw e;\n}","preventionTips":["Operate on a fetched message object so id is always present.","Add an assertion for message.id before deleteMessage.","Do not pass freshly-constructed (pre-send) messages to delete."],"tags":["apps-engine","message","delete","validation","argument-validation"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}