RocketChat/Rocket.Chat · error · Error

error-invalid-room

error-invalid-room

Error message

error-invalid-room

What it means

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.

Source

Thrown at apps/meteor/server/lib/rooms/banUserFromRoom.ts:70

		u: byUser,
	});

	// Send 'removed' so the client drops the room stream/socket subscription.
	// The record still exists in DB with status BANNED for access-control purposes.
	void notifyOnSubscriptionChanged(subscription, 'removed');
	void notifyOnRoomChangedById(room._id);
};

/**
 * Bans a user from the given room by updating the subscription status to BANNED,
 * removing them from member listings, and triggering all standard callbacks.
 * Used for local actions (UI or API) that should propagate normally to federation
 * and other subscribers.
 */
export const banUserFromRoom = async function (rid: string, user: IUser, byUser: IUser): Promise<void> {
	const room = await Rooms.findOneById(rid);
	if (!room) {
		throw new Error('error-invalid-room');
	}

	await performUserBan(room, user, byUser);

	void afterBanFromRoomCallback.run({ bannedUser: user, userWhoBanned: byUser }, room);
};

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Validate the rid (rooms.info API / Rooms.findOneById) before banning.
  2. Refresh room references in scripts or the moderation UI.
  3. Treat as stale state and drop the action.

Example fix

// before
await banUserFromRoom(rid, user, byUser); // throws 'error-invalid-room'

// after
const room = await Rooms.findOneById(rid, { projection: { _id: 1 } });
if (room) {
  await banUserFromRoom(rid, user, byUser);
}
Defensive patterns

Strategy: validation

Validate before calling

const room = await Rooms.findOneById(rid, { projection: { _id: 1 } });
if (!room) {
  // skip the ban: room no longer exists
}

Try / catch

try {
  await banUserFromRoom(rid, user, byUser);
} catch (error: any) {
  if (error?.message === 'error-invalid-room') {
    // plain Error, not Meteor.Error: match on the message and drop the action
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Moderation actions racing room deletion; tools using stale room ids; typos in API payloads.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/eec0e2af97dae56e. Report an issue: GitHub.