{"record":{"id":"f4dccf39a8288023","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-message-f4dccf","errorCode":"error-invalid-message","errorMessage":"Invalid message","messagePattern":"Invalid message","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/messages/followMessage.ts","lineNumber":29,"sourceCode":"import { follow } from '../../lib/messaging/threads/functions';\nimport { notifyOnMessageChange } from '../../lib/notifyListener';\nimport { settings } from '../../settings';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tfollowMessage(message: { mid: IMessage['_id'] }): false | undefined;\n\t}\n}\n\nexport const followMessage = async (user: IUser, { mid }: { mid: IMessage['_id'] }): Promise<false | undefined> => {\n\tif (mid && !settings.get('Threads_enabled')) {\n\t\tthrow new Meteor.Error('error-not-allowed', 'not-allowed', { method: 'followMessage' });\n\t}\n\n\tconst message = await Messages.findOneById(mid);\n\tif (!message) {\n\t\tthrow new Meteor.Error('error-invalid-message', 'Invalid message', {\n\t\t\tmethod: 'followMessage',\n\t\t});\n\t}\n\n\tif (!(await canAccessRoomIdAsync(message.rid, user._id))) {\n\t\tthrow new Meteor.Error('error-not-allowed', 'not-allowed', { method: 'followMessage' });\n\t}\n\n\tconst id = message.tmid || message._id;\n\n\tconst followResult = await follow({ tmid: id, uid: user._id });\n\n\tvoid notifyOnMessageChange({\n\t\tid,\n\t});\n\n\tconst isFollowed = true;\n\tawait Apps.self?.triggerEvent(AppEvents.IPostMessageFollowed, message, user, isFollowed);","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/followMessage.ts#L11-L47","documentation":"followMessage resolves the id via Messages.findOneById(mid); when no message matches it throws 'error-invalid-message'. The message may never have existed, or may have been deleted or purged between the client rendering a follow affordance and the call landing on the server.","triggerScenarios":"Meteor.call('followMessage', { mid }) with a mistyped id, the id of a deleted message, or a race where retention/purge removed the message after render.","commonSituations":"Follow buttons rendered from stale message lists; message-retention policies purging old messages; ids corrupted or truncated in deep links.","solutions":["Only offer follow for messages from a live, fresh message payload (current subscription data)","Handle 'error-invalid-message' by refreshing the thread state and hiding the follow affordance","For deep links, verify the message still exists (jump-to-message) before exposing follow"],"exampleFix":"// before\nawait Meteor.callAsync('followMessage', { mid });\n\n// after\ntry {\n  await Meteor.callAsync('followMessage', { mid });\n} catch (e) {\n  if (e.error === 'error-invalid-message') {\n    // message gone: drop it from local cache, stop offering follow\n  }\n}","handlingStrategy":"try-catch","validationCode":"const message = Messages.findOne({ _id: mid }); // local cache check\nif (!message) {\n  // do not offer follow for messages not in the current store\n}\nMeteor.call('followMessage', { mid });","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('followMessage', { mid });\n} catch (e) {\n  if ((e as Meteor.Error).error === 'error-invalid-message') {\n    // message deleted concurrently: purge from cache, hide follow\n  }\n}","preventionTips":["Only offer follow for messages present in the live subscription data","Handle deletion races gracefully — retention purges can remove messages at any time","Validate deep-link mids (jump-to-message) before enabling actions on them"],"tags":["meteor","messages","threads","resource-not-found"],"backgroundTag":"message-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}