RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-room

error-invalid-room

Error message

Invalid room

What it means

Thrown by saveRoomName when Rooms.findOneById(rid) returns null (saveRoomName.ts:53) — no room document exists for that id before any rename logic runs. Unlike the saveRoom* Match.test guards, this proves a string rid was given but resolves to nothing. Code 'error-invalid-room', details { function: 'RocketChat.saveRoomdisplayName' } (note the legacy typo in the function name).

Source

Thrown at apps/meteor/server/lib/rooms/settings/saveRoomName.ts:53

		Subscriptions.updateNameAndAlertByRoomId(rid, slugifiedRoomName, displayName),
	]);

	if (responses[1]?.modifiedCount) {
		void notifyOnSubscriptionChangedByRoomId(rid);
	}

	return responses;
};

export async function saveRoomName(
	rid: string,
	displayName: string | undefined,
	user: IUser,
	sendMessage = true,
): Promise<string | undefined> {
	const room = await Rooms.findOneById(rid);
	if (!room) {
		throw new Meteor.Error('error-invalid-room', 'Invalid room', {
			function: 'RocketChat.saveRoomdisplayName',
		});
	}

	if (roomCoordinator.getRoomDirectives(room.t).preventRenaming()) {
		throw new Meteor.Error('error-not-allowed', 'Not allowed', {
			function: 'RocketChat.saveRoomdisplayName',
		});
	}

	await Room.beforeNameChange(room);

	if (isRoomNativeFederated(room)) {
		displayName = `${displayName}:${room.federation.mrid.split(':').pop()}`;
	}

	if (displayName === room.name) {
		return;

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Verify the room exists: Rooms.findOneById(rid) before calling, and surface 'room not found' to the client
  2. Reload the room list in the UI and retry against an existing room
  3. Check for id truncation when rid travels through logs/queues
  4. Confirm you are pointed at the right database/environment

Example fix

// before
await saveRoomName(rid, displayName, user);

// after
const room = await Rooms.findOneById(rid);
if (!room) {
	throw new Meteor.Error('error-invalid-room', 'Room not found — it may have been deleted');
}
await saveRoomName(rid, displayName, user);
Defensive patterns

Strategy: validation

Validate before calling

const room = await Rooms.findOneById(rid);
if (!room) {
	throw new Meteor.Error('error-invalid-room', 'Room not found — it may have been deleted');
}
await saveRoomName(rid, displayName, user);

Try / catch

try {
	await saveRoomName(rid, displayName, user);
} catch (e) {
	if (e instanceof Meteor.Error && e.error === 'error-invalid-room') {
		// room vanished: refresh the client's room list instead of retrying
	}
}

Prevention

When it happens

Trigger: Renaming a room that was deleted between the client load and the save; rid typo/truncation; room exists only in another database/environment; archived-and-purged room still open in a stale UI tab.

Common situations: Two admins where one deletes the channel while the other edits settings; federation/replication lag; stale browser sessions hitting renamed/removed rooms.

Related errors


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