RocketChat/Rocket.Chat · error · Error
Message not found
Error message
Message not found
What it means
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.
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.
Example fix
// before
const msg = await chat.getMessageByID(mid);
// after
const msg = await chat.findMessageByID(mid);
if (!msg) {
dispatchToastMessage({ type: 'error', message: t('Message_not_found') });
return;
} Defensive patterns
Strategy: validation
Validate before calling
const msg = await chat.findMessageByID(mid);
if (!msg) {
// deleted, hidden, or inaccessible — do not call the strict getter
return;
}
const strict = msg; Try / catch
try {
const msg = await chat.getMessageByID(mid);
} catch (e) {
if (e instanceof Error && e.message === 'Message not found') {
dispatchToastMessage({ type: 'error', message: t('Message_not_found') });
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@2f18297792 (2026-08-18).
Data as JSON: /api/errors/642194e719ba549f.
Report an issue: GitHub.
Appendix: source
Thrown at apps/meteor/client/lib/chats/data.ts:45
_id: originalMessage?._id ?? Random.id(),
rid: effectiveRID,
...(effectiveTMID && {
tmid: effectiveTMID,
...(sendToChannel && { tshow: sendToChannel }),
}),
msg,
} as IMessage;
};
const findMessageByID = async (mid: IMessage['_id']): Promise<IMessage | null> =>
Messages.state.find((record) => record._id === mid && record._hidden !== true) ??
sdk.rest.get('/v1/chat.getMessage', { msgId: mid }).then((response) => mapMessageFromApi(response.message));
const getMessageByID = async (mid: IMessage['_id']): Promise<IMessage> => {
const message = await findMessageByID(mid);
if (!message) {
throw new Error('Message not found');
}
return message;
};
const findLastMessage = async (): Promise<IMessage | undefined> =>
Messages.state.findFirst(
(record) => record.rid === rid && (tmid ? record.tmid === tmid : !record.tmid) && record._hidden !== true,
(a, b) => b.ts.getTime() - a.ts.getTime(),
);
const getLastMessage = async (): Promise<IMessage> => {
const message = await findLastMessage();
if (!message) {
throw new Error('Message not found');
}
View on GitHub (pinned to 2f18297792)