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
Thrown by addRoomOwner() in apps/meteor/server/meteor-methods/rooms/addRoomOwner.ts:58 when Subscriptions.findOneByRoomIdAndUserId(rid, user._id) returns null — the target user exists but has no subscription for that room, i.e. is not a member. Rocket.Chat roles like 'owner' are stored on the room subscription, so promoting a non-member is impossible.
Source
Thrown at apps/meteor/server/meteor-methods/rooms/addRoomOwner.ts:58
});
}
if (isFederated && !isFederationEnabled()) {
throw new FederationMatrixInvalidConfigurationError('unable to change room owners');
}
const user = await Users.findOneById(userId);
if (!user?.username) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'addRoomOwner',
});
}
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: 'addRoomOwner',
});
}
if (subscription.roles && Array.isArray(subscription.roles) === true && subscription.roles.includes('owner') === true) {
throw new Meteor.Error('error-user-already-owner', 'User is already an owner', {
method: 'addRoomOwner',
});
}
await beforeChangeRoomRole.run({ fromUserId, userId, room, role: 'owner' });
const addRoleResponse = await Subscriptions.addRoleById(subscription._id, 'owner');
await syncRoomRolePriorityForUserAndRoom(userId, rid, subscription.roles?.concat(['owner']) || ['owner']);
if (addRoleResponse.modifiedCount) {
void notifyOnSubscriptionChangedById(subscription._id);
}View on GitHub (pinned to b2c16d5842)
Solutions
- Check membership first: const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId); and require sub before promoting.
- If the user should be a member, add them first (e.g. POST /v1/channels.invite or the addUsersToRoom flow), then grant 'owner'.
- If they were removed by mistake, re-invite and retry.
- Prefer the REST endpoints POST /v1/channels.addOwner / POST /v1/groups.addOwner which validate membership with clearer API error bodies.
Example fix
// before
await addRoomOwner(uid, rid, targetUserId);
// after
const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, targetUserId, { projection: { _id: 1 } });
if (!sub) throw new Error('target is not a member of the room; invite first');
await addRoomOwner(uid, rid, targetUserId); Defensive patterns
Strategy: validation
Validate before calling
const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId, { projection: { _id: 1 } });
if (!sub) throw new Error('target is not a member; invite before promoting'); Type guard
const isMember = (s: unknown): s is { _id: string } => Boolean(s && typeof (s as any)?._id === 'string'); Try / catch
try {
await addRoomOwner(uid, rid, userId);
} catch (e) {
if (e instanceof Meteor.Error && e.error === 'error-user-not-in-room') {
// invite the user first, then retry the promotion
}
} Prevention
- Gate promote/owner UI on the membership list of the room, not a global user picker.
- For bulk scripts, diff desired owners against current subscriptions first.
- Re-check membership immediately before the call in flows where users may leave concurrently.
When it happens
Trigger: Calling addRoomOwner for a user who never joined or was never invited; the user left the room or was kicked before the promotion; the user was removed when the room was converted to a private team channel; racing with a concurrent leave/remove operation.
Common situations: Admin scripts promoting users by a list that predates a room cleanup; UI flows where the operator types a username not currently in the channel; ops run right after a mass-remove of inactive members; stale membership assumptions after team/channel conversion.
Related errors
- User is not in this room
- error-cant-invite-for-direct-room
- error-user-is-banned
- Room not found
- Subscription not found
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/75b8058f7b6cdb9b.
Report an issue: GitHub.