{"record":{"id":"642194e719ba549f","repo":"RocketChat/Rocket.Chat","slug":"message-not-found","errorCode":null,"errorMessage":"Message not found","messagePattern":"Message not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/client/lib/chats/data.ts","lineNumber":45,"sourceCode":"\t\t\t_id: originalMessage?._id ?? Random.id(),\n\t\t\trid: effectiveRID,\n\t\t\t...(effectiveTMID && {\n\t\t\t\ttmid: effectiveTMID,\n\t\t\t\t...(sendToChannel && { tshow: sendToChannel }),\n\t\t\t}),\n\t\t\tmsg,\n\t\t} as IMessage;\n\t};\n\n\tconst findMessageByID = async (mid: IMessage['_id']): Promise<IMessage | null> =>\n\t\tMessages.state.find((record) => record._id === mid && record._hidden !== true) ??\n\t\tsdk.rest.get('/v1/chat.getMessage', { msgId: mid }).then((response) => mapMessageFromApi(response.message));\n\n\tconst getMessageByID = async (mid: IMessage['_id']): Promise<IMessage> => {\n\t\tconst message = await findMessageByID(mid);\n\n\t\tif (!message) {\n\t\t\tthrow new Error('Message not found');\n\t\t}\n\n\t\treturn message;\n\t};\n\n\tconst findLastMessage = async (): Promise<IMessage | undefined> =>\n\t\tMessages.state.findFirst(\n\t\t\t(record) => record.rid === rid && (tmid ? record.tmid === tmid : !record.tmid) && record._hidden !== true,\n\t\t\t(a, b) => b.ts.getTime() - a.ts.getTime(),\n\t\t);\n\n\tconst getLastMessage = async (): Promise<IMessage> => {\n\t\tconst message = await findLastMessage();\n\n\t\tif (!message) {\n\t\t\tthrow new Error('Message not found');\n\t\t}\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/client/lib/chats/data.ts#L27-L63","documentation":"Thrown by getMessageByID in the chats data layer when neither the local reactive store (Messages.state) nor the server fallback (GET /v1/chat.getMessage) returned a message for the given mid. findMessageByID first checks local state (excluding hidden messages) then queries the server; if both yield nothing, the message truly does not exist or is inaccessible.","triggerScenarios":"Calling getMessageByID(mid) where mid does not exist, was deleted, belongs to a room the user cannot read, or the server returned no message in the chat.getMessage response (response.message falsy). The local lookup also filters out _hidden === true records, so a hidden message in local state still falls through to the server.","commonSituations":"Stale message id from an old notification/deep link; the message was deleted between fetch and access; the user lacks 'read-message'/'preview-room' permission for the room; the room is a private channel the user was removed from; a deep link with a truncated/typo'd id.","solutions":["Verify the mid is correct and not truncated (deep links/notifications can mangle ids).","Confirm the user has read access to the room the message belongs to.","Handle the thrown error to show a 'message no longer available' state instead of crashing.","If the message was deleted, refresh the thread/room list to reflect the new state.","For hidden messages, ensure the caller expects a hidden message to be treated as absent."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify read access before lookup\nif (!hasAtLeastOnePermission('read-message', roomId)) {\n  throw new Error('No read access');\n}","typeGuard":"function isFoundMessage(m: IMessage | null | undefined): m is IMessage {\n  return m != null;\n}","tryCatchPattern":"try {\n  const msg = await getMessageByID(mid);\n} catch (e) {\n  if ((e as Error).message === 'Message not found') {\n    showMessageUnavailable();\n  }\n}","preventionTips":["Validate the mid is complete and not truncated from a deep link.","Confirm the user has read access to the message's room.","Handle the error to show a 'message unavailable' state instead of crashing."],"tags":["message","rest","reactive-store","permission","deep-link"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}