{"record":{"id":"0339404539600a60","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-033940","errorCode":"error-invalid-room","errorMessage":"Invalid room","messagePattern":"Invalid room","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/removeRoomOwner.ts","lineNumber":28,"sourceCode":"import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\nimport { notifyOnSubscriptionChangedById } from '../../lib/notifyListener';\nimport { syncRoomRolePriorityForUserAndRoom } from '../../lib/roles/syncRoomRolePriority';\nimport { settings } from '../../settings';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tremoveRoomOwner(rid: string, userId: string): boolean;\n\t}\n}\n\nexport const removeRoomOwner = async (fromUserId: string, rid: string, userId: string): Promise<boolean> => {\n\tcheck(rid, String);\n\tcheck(userId, String);\n\n\tconst room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1, federation: 1 } });\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', {\n\t\t\tmethod: 'removeRoomOwner',\n\t\t});\n\t}\n\n\tif (!(await hasPermissionAsync(fromUserId, 'set-owner', rid)) && !isRoomFederated(room)) {\n\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', {\n\t\t\tmethod: 'removeRoomOwner',\n\t\t});\n\t}\n\n\tconst user = await Users.findOneById(userId);\n\tif (!user?.username) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'removeRoomOwner',\n\t\t});\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, user._id);","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/removeRoomOwner.ts#L10-L46","documentation":"removeRoomOwner begins with Rooms.findOneById(rid, ...) and throws error-invalid-room when no document matches. As with the moderator variant, this precedes permission checks, so a nonexistent, deleted, or malformed room ID always produces it. rid must be the room's _id.","triggerScenarios":"Passing a room name instead of its _id; the room was deleted before the demotion call executed; truncated or mistyped ID string.","commonSituations":"Stale channel settings page after the channel was deleted; environment-to-environment data copies with different IDs; automation composing rid from slugs.","solutions":["Look the room up first (client Rooms collection or GET /api/v1/rooms.info?roomId=) and pass the returned _id","Reload the room context when the call fails so the UI drops dead references","Always pass _id, never name, for rid"],"exampleFix":"// before\nawait Meteor.callAsync('removeRoomOwner', roomName, userId);\n\n// after\nconst room = Rooms.findOne({ name: roomName });\nif (!room) throw new Error('room gone');\nawait Meteor.callAsync('removeRoomOwner', room._id, userId);","handlingStrategy":"validation","validationCode":"const room = Rooms.findOne({ _id: rid });\nif (!room) {\n  // stale rid: refetch rooms and abort\n}","typeGuard":"const isExistingRoom = (rid: string | undefined): rid is string =>\n  typeof rid === 'string' && rid.length > 0 && Rooms.findOne({ _id: rid }) != null;","tryCatchPattern":"try {\n  await Meteor.callAsync('removeRoomOwner', rid, userId);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-room') {\n    // room gone: refresh UI, do not retry same rid\n  }\n}","preventionTips":["Resolve rid via lookup; never synthesize from names","Drop dead room references after delete events","Validate IDs before method calls"],"tags":["rooms","meteor-methods","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-23T08:17:48.524Z"}