{"record":{"id":"cd70e0d04f3ae4ef","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-cd70e0","errorCode":"error-invalid-room","errorMessage":"error-invalid-room","messagePattern":"error-invalid-room","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/users/blockUser.ts","lineNumber":12,"sourceCode":"import { Subscriptions, Rooms } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { RoomMemberActions } from '../../../definition/IRoomTypeConfig';\nimport { notifyOnSubscriptionChangedByRoomIdAndUserIds } from '../notifyListener';\nimport { roomCoordinator } from '../rooms/roomCoordinator';\n\nexport const blockUserMethod = async (userId: string, { rid, blocked }: { rid: string; blocked: string }): Promise<void> => {\n\tconst room = await Rooms.findOne({ _id: rid });\n\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'blockUser' });\n\t}\n\n\tif (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.BLOCK, userId))) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'blockUser' });\n\t}\n\n\tconst [blockedUser, blockerUser] = await Promise.all([\n\t\tSubscriptions.findOneByRoomIdAndUserId(rid, blocked, { projection: { _id: 1 } }),\n\t\tSubscriptions.findOneByRoomIdAndUserId(rid, userId, { projection: { _id: 1 } }),\n\t]);\n\n\tif (!blockedUser || !blockerUser) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'blockUser' });\n\t}\n\n\tconst [blockedResponse, blockerResponse] = await Subscriptions.setBlockedByRoomId(rid, blocked, userId);\n\n\tconst listenerUsers = [...(blockedResponse?.modifiedCount ? [blocked] : []), ...(blockerResponse?.modifiedCount ? [userId] : [])];","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/users/blockUser.ts#L1-L30","documentation":"blockUserMethod throws error-invalid-room with method 'blockUser' when Rooms.findOne({ _id: rid }) returns null: no room exists with that id. This is the first of three identical-code guards in the method (not found, wrong type, missing subscription).","triggerScenarios":"Meteor.call('blockUser', [{ rid, blocked }]) or the im.blockUser REST route with a stale rid: the room was deleted while the client still held the id, a typo in the id, or a rid copied from another workspace/environment.","commonSituations":"Client cached a DM room id across a room deletion or re-installation; test fixtures using fabricated ObjectIds; environment mismatch (dev id used against prod).","solutions":["Refresh the room list and confirm the room still exists (GET /api/v1/rooms.info?roomId=...)","If the room was deleted, drop the local state pointing at it; there is nothing to block in","Verify the rid comes from the same server/deployment as the call"],"exampleFix":"// before\nMeteor.call('blockUser', { rid, blocked });\n\n// after\nconst room = await call('GET', 'rooms.info', { roomId: rid }); // throws clean 404 if deleted\nif (!room) throw new Error('Room no longer exists');\nMeteor.call('blockUser', { rid, blocked });","handlingStrategy":"validation","validationCode":"const room = await Rooms.findOneById(rid, { projections: { _id: 1 } });\nif (!room) throw new Error('Room does not exist (maybe deleted)');\nMeteor.call('blockUser', { rid, blocked });","typeGuard":"const isInvalidRoomError = (e: unknown): boolean =>\n  typeof e === 'object' && e !== null && 'error' in e && (e as { error?: string }).error === 'error-invalid-room';","tryCatchPattern":"try {\n  Meteor.call('blockUser', { rid, blocked });\n} catch (e) {\n  if (isInvalidRoomError(e) && /Invalid room/.test((e as { reason?: string }).reason ?? '')) {\n    invalidateCachedRoom(rid); // room is gone, refresh state\n  }\n}","preventionTips":["Invalidate cached room ids when rooms.info returns 404","Treat room deletion events (streamer) as a signal to drop stored rids","Never reuse ids across deployments"],"tags":["rooms","blocking","direct-messages","meteor-methods"],"backgroundTag":"room-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}