{"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/2f18297792c973da326be7253f497d239ea6f2b0/apps/meteor/client/lib/chats/data.ts#L27-L63","documentation":"getMessageByID() in the chat data layer throws 'Message not found' when findMessageByID returns null: the message is neither in the local Messages store (records with _hidden !== true are skipped) nor retrievable via GET /v1/chat.getMessage from the server. It is the strict variant of the finder and assumes the caller has already established the message exists.","triggerScenarios":"Calling getMessageByID with an id that was deleted server-side, a locally hidden record (_hidden === true, e.g. hidden by moderation or queued deletion), a message in a room the user cannot read, or an invalid/mistyped id; also a server error from the chat.getMessage fallback resolves to null.","commonSituations":"Jumping to a permalink whose target message was deleted; racing a delete with an edit/quote action; local cache cleared or evicted while the server copy is gone; message id taken from an unrelated workspace.","solutions":["Use findMessageByID instead and handle the null case gracefully.","Verify the message id and that the current user has read access to the target room.","If the message was hidden locally but still exists, reload it from the server / clear the _hidden flag before using the strict getter."],"exampleFix":"// before\nconst msg = await chat.getMessageByID(mid);\n\n// after\nconst msg = await chat.findMessageByID(mid);\nif (!msg) {\n  dispatchToastMessage({ type: 'error', message: t('Message_not_found') });\n  return;\n}","handlingStrategy":"validation","validationCode":"const msg = await chat.findMessageByID(mid);\nif (!msg) {\n  // deleted, hidden, or inaccessible — do not call the strict getter\n  return;\n}\nconst strict = msg;","typeGuard":null,"tryCatchPattern":"try {\n  const msg = await chat.getMessageByID(mid);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Message not found') {\n    dispatchToastMessage({ type: 'error', message: t('Message_not_found') });\n    return;\n  }\n  throw e;\n}","preventionTips":["Prefer the find* variants in UI code; reserve get* for invariants you have already checked.","Verify message ids come from the same workspace and the user can read the target room.","Treat _hidden records as absent — clear or reload them before strict lookups."],"tags":["messages","cache","rest-api"],"backgroundTag":"message-not-found","analyzedSha":"2f18297792c973da326be7253f497d239ea6f2b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}