{"record":{"id":"1a1d0773348fdae8","repo":"RocketChat/Rocket.Chat","slug":"error-action-not-allowed-1a1d07","errorCode":"error-action-not-allowed","errorMessage":"Not allowed","messagePattern":"Not allowed","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/messaging/unread/unreadMessages.ts","lineNumber":42,"sourceCode":"\t\t)[0];\n\n\t\tif (!lastMessage) {\n\t\t\tthrow new Meteor.Error('error-no-message-for-unread', 'There are no messages to mark unread', {\n\t\t\t\tmethod: 'unreadMessages',\n\t\t\t\taction: 'Unread_messages',\n\t\t\t});\n\t\t}\n\n\t\tconst setAsUnreadResponse = await Subscriptions.setAsUnreadByRoomIdAndUserId(lastMessage.rid, userId, lastMessage.ts);\n\t\tif (setAsUnreadResponse.modifiedCount) {\n\t\t\tvoid notifyOnSubscriptionChangedByRoomIdAndUserId(lastMessage.rid, userId);\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif (typeof firstUnreadMessage?._id !== 'string') {\n\t\tthrow new Meteor.Error('error-action-not-allowed', 'Not allowed', {\n\t\t\tmethod: 'unreadMessages',\n\t\t\taction: 'Unread_messages',\n\t\t});\n\t}\n\n\tconst originalMessage = await Messages.findOneById(firstUnreadMessage._id, {\n\t\tprojection: {\n\t\t\tu: 1,\n\t\t\trid: 1,\n\t\t\tts: 1,\n\t\t},\n\t});\n\tif (!originalMessage || userId === originalMessage.u._id) {\n\t\tthrow new Meteor.Error('error-action-not-allowed', 'Not allowed', {\n\t\t\tmethod: 'unreadMessages',\n\t\t\taction: 'Unread_messages',\n\t\t});\n\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/messaging/unread/unreadMessages.ts#L24-L60","documentation":"In the message branch of unreadMessages (no room argument given), the code requires firstUnreadMessage._id to be a string; otherwise it throws Meteor.Error('error-action-not-allowed', 'Not allowed'). It is an argument-shape guard: the payload must be an object like { _id: '<messageId>' } for the message-anchored unread flow.","triggerScenarios":"Meteor.call('unreadMessages') with firstUnreadMessage undefined/null, an object without _id, or a non-string _id (number/ObjectId), while also omitting the second room argument.","commonSituations":"Clients calling the method with no arguments expecting 'unread everything'; malformed payloads from integrations; refactors that changed the argument shape without updating callers.","solutions":["Pass a valid message anchor: Meteor.call('unreadMessages', { _id: messageId })","To mark a whole room unread from its last message, pass the room id as the second argument instead","Type the call site against the ServerMethods declaration so shape errors surface at compile time"],"exampleFix":"// before\nMeteor.call('unreadMessages'); // no message and no room\n\n// after\nMeteor.call('unreadMessages', { _id: firstUnreadMessageId }, rid);","handlingStrategy":"type-guard","validationCode":"const hasMessageAnchor = typeof firstUnreadMessage?._id === 'string';\nconst hasRoom = typeof room === 'string';\nif (hasMessageAnchor || hasRoom) {\n  Meteor.call('unreadMessages', firstUnreadMessage, room);\n}","typeGuard":"const isFirstUnreadPayload = (v: unknown): v is { _id: string } =>\n  typeof v === 'object' && v !== null && typeof (v as { _id?: unknown })._id === 'string';","tryCatchPattern":"Meteor.call('unreadMessages', first, rid, (err) => {\n  if (err?.error === 'error-action-not-allowed' && !first?._id && !rid) {\n    fixPayloadAndRetry(); // neither message anchor nor room was supplied\n  }\n});","preventionTips":["Type the call site against the ServerMethods declaration to catch shape errors at compile time","Always supply either a message { _id } or a room string - never neither","Centralize method invocation in typed wrappers so payloads cannot be built ad hoc"],"tags":["unread","invalid-arguments","ddp-method"],"backgroundTag":"invalid-method-arguments","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}