{"record":{"id":"eec0e2af97dae56e","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-eec0e2","errorCode":"error-invalid-room","errorMessage":"error-invalid-room","messagePattern":"error-invalid-room","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/rooms/banUserFromRoom.ts","lineNumber":70,"sourceCode":"\t\tu: byUser,\n\t});\n\n\t// Send 'removed' so the client drops the room stream/socket subscription.\n\t// The record still exists in DB with status BANNED for access-control purposes.\n\tvoid notifyOnSubscriptionChanged(subscription, 'removed');\n\tvoid notifyOnRoomChangedById(room._id);\n};\n\n/**\n * Bans a user from the given room by updating the subscription status to BANNED,\n * removing them from member listings, and triggering all standard callbacks.\n * Used for local actions (UI or API) that should propagate normally to federation\n * and other subscribers.\n */\nexport const banUserFromRoom = async function (rid: string, user: IUser, byUser: IUser): Promise<void> {\n\tconst room = await Rooms.findOneById(rid);\n\tif (!room) {\n\t\tthrow new Error('error-invalid-room');\n\t}\n\n\tawait performUserBan(room, user, byUser);\n\n\tvoid afterBanFromRoomCallback.run({ bannedUser: user, userWhoBanned: byUser }, room);\n};\n","sourceCodeStart":52,"sourceCodeEnd":77,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/rooms/banUserFromRoom.ts#L52-L77","documentation":"Plain Error('error-invalid-room') thrown by banUserFromRoom when Rooms.findOneById(rid) finds nothing: the ban targets a nonexistent room. Unlike most errors in this file it is a plain Error, not a Meteor.Error, so clients only receive the message string.","triggerScenarios":"The ban flow invoked with a rid that was deleted or malformed: room deleted while a moderation action was queued, or scripts operating on cached room lists.","commonSituations":"Moderation actions racing room deletion; tools using stale room ids; typos in API payloads.","solutions":["Validate the rid (rooms.info API / Rooms.findOneById) before banning.","Refresh room references in scripts or the moderation UI.","Treat as stale state and drop the action."],"exampleFix":"// before\nawait banUserFromRoom(rid, user, byUser); // throws 'error-invalid-room'\n\n// after\nconst room = await Rooms.findOneById(rid, { projection: { _id: 1 } });\nif (room) {\n  await banUserFromRoom(rid, user, byUser);\n}","handlingStrategy":"validation","validationCode":"const room = await Rooms.findOneById(rid, { projection: { _id: 1 } });\nif (!room) {\n  // skip the ban: room no longer exists\n}","typeGuard":null,"tryCatchPattern":"try {\n  await banUserFromRoom(rid, user, byUser);\n} catch (error: any) {\n  if (error?.message === 'error-invalid-room') {\n    // plain Error, not Meteor.Error: match on the message and drop the action\n  }\n}","preventionTips":["Re-check room existence in moderation tooling before actions.","It is a plain Error - match on message 'error-invalid-room'.","Refresh room references after deletions/archival."],"tags":["rooms","moderation","validation"],"backgroundTag":"room-not-found","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"}