RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-room
error-invalid-room
Error message
Invalid room
What it means
executeGetRoomRoles throws 'error-invalid-room' when Rooms.findOneById(rid) returns null: no room document exists with the supplied id. Unlike sibling methods that reuse 'error-not-allowed', this one names the problem accurately - the rid simply does not match any room.
Source
Thrown at apps/meteor/server/meteor-methods/rooms/getRoomRoles.ts:27
import { settings } from '../../settings';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
getRoomRoles(rid: IRoom['_id']): RoomRoles[];
}
}
export const executeGetRoomRoles = async (rid: IRoom['_id'], fromUser?: IUser | null) => {
check(rid, String);
if (!fromUser && settings.get('Accounts_AllowAnonymousRead') === false) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getRoomRoles' });
}
const room = await Rooms.findOneById(rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getRoomRoles' });
}
if (fromUser && !(await canAccessRoomAsync(room, fromUser))) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getRoomRoles' });
}
return getRoomRoles(rid);
};
View on GitHub (pinned to b2c16d5842)
Solutions
- Re-verify the rid against the current rooms subscription or db.rooms before fetching roles
- Handle 'error-invalid-room' by discarding cached state for that rid
- Serialize room-close and roles-fetch logic so the fetch cannot outlive the room
Example fix
// before
const roles = await Meteor.callAsync('getRoomRoles', rid);
// after - confirm the room is still open/live before fetching
if (!RoomManager.getOpenedRoomByRid(rid)) return [];
const roles = await Meteor.callAsync('getRoomRoles', rid); Defensive patterns
Strategy: validation
Validate before calling
if (typeof rid !== 'string' || rid.length !== 17) throw new Error('malformed room id');
if (!RoomManager.getOpenedRoomByRid(rid)) return []; // room no longer live
const roles = await Meteor.callAsync('getRoomRoles', rid); Try / catch
try {
const roles = await Meteor.callAsync('getRoomRoles', rid);
} catch (e) {
if (e instanceof Meteor.Error && e.error === 'error-invalid-room') {
discardRoomState(rid); // room deleted - stop fetching roles for it
}
} Prevention
- Cancel in-flight role fetches when the room view closes
- Validate rids against the live rooms subscription before use
- 'error-invalid-room' here genuinely means not-found, unlike sibling methods
When it happens
Trigger: Calling getRoomRoles (or executeGetRoomRoles) with a deleted room id, a room id from another workspace, or a malformed value that still passes check(rid, String); races where roles are fetched right as a room is deleted.
Common situations: UI closing over a room while a parallel roles fetch is in flight; ids persisted from before a room deletion; copy-paste of rids between test and production databases.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/55cd0803a4d3ed2d.
Report an issue: GitHub.