{"record":{"id":"faa372ac5d22831e","repo":"RocketChat/Rocket.Chat","slug":"error-message-not-found","errorCode":"error-message-not-found","errorMessage":"The provided \"messageId\" does not match any existing message.","messagePattern":"The provided \"messageId\" does not match any existing message\\.","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/chat.ts","lineNumber":213,"sourceCode":"\t\t\t\t200: ajv.compile<{ message: IMessage }>({\n\t\t\t\t\ttype: 'object',\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tmessage: { $ref: '#/components/schemas/IMessage' },\n\t\t\t\t\t\tsuccess: {\n\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\trequired: ['message', 'success'],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t}),\n\t\t\t},\n\t\t},\n\t\tasync function action() {\n\t\t\tconst msg = await Messages.findOneById(this.bodyParams.messageId);\n\n\t\t\tif (!msg) {\n\t\t\t\tthrow new Meteor.Error('error-message-not-found', 'The provided \"messageId\" does not match any existing message.');\n\t\t\t}\n\n\t\t\tconst pinnedMessage = await pinMessage(msg, this.userId);\n\n\t\t\tconst [message] = await normalizeMessagesForUser([pinnedMessage], this.userId);\n\n\t\t\treturn API.v1.success({\n\t\t\t\tmessage,\n\t\t\t});\n\t\t},\n\t)\n\t.post(\n\t\t'chat.unPinMessage',\n\t\t{\n\t\t\tauthRequired: true,\n\t\t\tbody: isChatUnpinMessageProps,\n\t\t\tresponse: {\n\t\t\t\t400: validateBadRequestErrorResponse,","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/chat.ts#L195-L231","documentation":"Thrown by the chat.pinMessage endpoint when Messages.findOneById(this.bodyParams.messageId) returns null. The messageId was parsed from the body but no message with that _id exists. Uses Meteor.Error code 'error-message-not-found'.","triggerScenarios":"POST chat.pinMessage with a messageId that does not correspond to any message document (deleted, typo, wrong workspace).","commonSituations":"Pinning a message that was deleted between render and click; messageId copied from another server; client cache holding a stale id.","solutions":["Verify the messageId exists (e.g., via chat.getMessage) before pinning.","Refresh the message context and discard ids for messages that no longer load.","Handle error-message-not-found in the client by removing the pin option from deleted messages."],"exampleFix":"// before\nawait fetch('/api/v1/chat.pinMessage', { method: 'POST', body: JSON.stringify({ messageId }) });\n\n// after\nconst exists = await fetchMessage(messageId);\nif (!exists) {\n  notifyUser('Message no longer exists');\n  return;\n}\nawait fetch('/api/v1/chat.pinMessage', { method: 'POST', body: JSON.stringify({ messageId }) });","handlingStrategy":"validation","validationCode":"async function pinIfExists(messageId, userId) {\n  const msg = await Messages.findOneById(messageId);\n  if (!msg) throw new Error('message-not-found');\n  return pinMessage(msg, userId);\n}","typeGuard":"function isExistingMessage(msg) {\n  return Boolean(msg) && typeof msg._id === 'string' && typeof msg.rid === 'string';\n}","tryCatchPattern":"try {\n  await api.pinMessage({ messageId });\n} catch (e) {\n  if (e.error === 'error-message-not-found') {\n    removeMessageFromUI(messageId); // stale id\n    return;\n  }\n  throw e;\n}","preventionTips":["Verify the message exists before pinning.","Discard stale messageIds after a refresh.","Hide pin actions on messages that failed to load."],"tags":["chat","message-not-found","pin","rest-api"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}