{"record":{"id":"c722388c80f5a9f7","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-message","errorCode":"error-invalid-message","errorMessage":"Invalid message","messagePattern":"Invalid message","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/meteor-methods/getReadReceipts.ts","lineNumber":27,"sourceCode":"import { methodDeprecationLogger } from '../../../server/lib/deprecationWarningLogger';\nimport { ReadReceipt } from '../lib/message-read-receipt/ReadReceipt';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tgetReadReceipts(options: { messageId: IMessage['_id'] }): IReadReceiptWithUser[];\n\t}\n}\n\nexport const getReadReceiptsFunction = async function (messageId: IMessage['_id'], userId: string): Promise<IReadReceiptWithUser[]> {\n\tif (!License.hasModule('message-read-receipt')) {\n\t\tthrow new Meteor.Error('error-action-not-allowed', 'This is an enterprise feature', { method: 'getReadReceipts' });\n\t}\n\tcheck(messageId, String);\n\n\tconst message = await Messages.findOneById(messageId, { projection: { _id: 1, rid: 1, receiptsArchived: 1 } });\n\tif (!message) {\n\t\tthrow new Meteor.Error('error-invalid-message', 'Invalid message', {\n\t\t\tmethod: 'getReadReceipts',\n\t\t});\n\t}\n\n\tif (!(await canAccessRoomIdAsync(message.rid, userId))) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getReadReceipts' });\n\t}\n\n\treturn ReadReceipt.getReceipts(message);\n};\n\nMeteor.methods<ServerMethods>({\n\tasync getReadReceipts({ messageId }) {\n\t\tmethodDeprecationLogger.method('getReadReceipts', '9.0.0', '/v1/chat.getMessageReadReceipts');\n\n\t\tcheck(messageId, String);\n\n\t\tconst uid = Meteor.userId();","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/meteor-methods/getReadReceipts.ts#L9-L45","documentation":"Thrown by getReadReceiptsFunction when Messages.findOneById(messageId) returns null. The lookup projects _id, rid, and receiptsArchived; a missing record means the message id does not correspond to an existing message. Code is 'error-invalid-message'.","triggerScenarios":"Calling getReadReceipts with a messageId that does not exist, was deleted, or has not been inserted yet (eventual-consistency lag).","commonSituations":"Client holds a stale message id after deletion; message id mistyped or swapped; a message deleted by retention policy while its read-receipt panel was open.","solutions":["Validate the messageId exists (Messages.findOneById) before calling the method.","Handle the error in the client and close the read-receipt panel with a 'message not found' notice.","Check retention/purge policies if valid messages disappear."],"exampleFix":"// before\nconst receipts = await getReadReceiptsFunction(messageId, uid);\n\n// after\nconst msg = await Messages.findOneById(messageId, { projection: { _id: 1 } });\nif (!msg) throw new Error('Message not found');\nconst receipts = await getReadReceiptsFunction(messageId, uid);","handlingStrategy":"validation","validationCode":"const msg = await Messages.findOneById(messageId, { projection: { _id: 1 } });\nif (!msg) throw new Error('Message not found');\nconst receipts = await getReadReceiptsFunction(messageId, uid);","typeGuard":"function isMessageId(id: unknown): id is string {\n  return typeof id === 'string' && id.length > 0;\n}","tryCatchPattern":"try {\n  await getReadReceiptsFunction(messageId, uid);\n} catch (e) {\n  if (isMeteorError(e, 'error-invalid-message')) {\n    closeReadReceiptPanel('Message no longer exists.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Validate messageId existence before calling.","Close the read-receipt panel on delete events.","Watch retention/purge jobs that remove messages."],"tags":["read-receipts","validation","message"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}