RocketChat/Rocket.Chat · error · Meteor.Error

error-user-not-in-room

error-user-not-in-room

Error message

User is not in this room

What it means

addRoomLeader then looks up the target's membership with Subscriptions.findOneByRoomIdAndUserId(rid, user._id); a null subscription means the user is not in the room, so they cannot be promoted to leader. The role must be attached to an existing subscription.

Source

Thrown at apps/meteor/server/meteor-methods/rooms/addRoomLeader.ts:42

	if (!(await hasPermissionAsync(fromUserId, 'set-leader', rid))) {
		throw new Meteor.Error('error-not-allowed', 'Not allowed', {
			method: 'addRoomLeader',
		});
	}

	const user = await Users.findOneById(userId);

	if (!user?.username) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', {
			method: 'addRoomLeader',
		});
	}

	const subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, user._id);

	if (!subscription) {
		throw new Meteor.Error('error-user-not-in-room', 'User is not in this room', {
			method: 'addRoomLeader',
		});
	}

	if (subscription.roles && Array.isArray(subscription.roles) === true && subscription.roles.includes('leader') === true) {
		throw new Meteor.Error('error-user-already-leader', 'User is already a leader', {
			method: 'addRoomLeader',
		});
	}

	const addRoleResponse = await Subscriptions.addRoleById(subscription._id, 'leader');
	await syncRoomRolePriorityForUserAndRoom(userId, rid, subscription.roles?.concat(['leader']) || ['leader']);

	if (addRoleResponse.modifiedCount) {
		void notifyOnSubscriptionChangedById(subscription._id);
	}

	const fromUser = await Users.findOneById(fromUserId);

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Add the user to the room first (addUserToRoom / channels.invite), then re-run the role change.
  2. Refresh membership state in the UI before offering role actions.
  3. Treat the error as a prompt to re-check membership rather than retrying unchanged.
Defensive patterns

Strategy: validation

Validate before calling

// confirm the target is a member of the room before promoting
const sub = RocketChat.models?.Subscriptions?.findOne({ rid, 'u._id': userId });
if (!sub) {
	throw new Error('User is not in this room - invite first');
}

Try / catch

try {
	await Meteor.callAsync('addRoomLeader', rid, userId);
} catch (e: any) {
	if (e?.error === 'error-user-not-in-room') {
		// invite the user first (channels.invite), then retry the promotion
	}
}

Prevention

When it happens

Trigger: The target left or was removed from the channel before the role change landed; calling addRoomLeader for a user who was never added to the room.

Common situations: Races between a user leaving and an admin promoting them; member lists not refreshed after removals.

Related errors


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