RocketChat/Rocket.Chat · error · Meteor.Error
user-not-found
user-not-found
Error message
user-not-found
What it means
Meteor.Error('user-not-found') thrown by addUserToRoom when Users.findOneById(user._id) returns nothing: the user being added no longer exists. Note the unconventional code (no 'error-' prefix) and the empty message.
Source
Thrown at apps/meteor/server/lib/rooms/addUserToRoom.ts:48
skipSystemMessage?: boolean;
skipAlertSound?: boolean;
createAsHidden?: boolean;
} = {},
): Promise<boolean | undefined> => {
const now = new Date();
const room = await Rooms.findOneById(rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
method: 'addUserToRoom',
});
}
const userToBeAdded = await Users.findOneById(user._id);
const roomDirectives = roomCoordinator.getRoomDirectives(room.t);
if (!userToBeAdded) {
throw new Meteor.Error('user-not-found');
}
if (
!(await roomDirectives.allowMemberAction(room, RoomMemberActions.JOIN, userToBeAdded._id)) &&
!(await roomDirectives.allowMemberAction(room, RoomMemberActions.INVITE, userToBeAdded._id))
) {
return;
}
try {
const inviterUser = inviter && ((await Users.findOneById(inviter._id)) || undefined);
// Not "duplicated": we're moving away from callbacks so this is a patch function. We should migrate the next one to be a patch or use this same patch, instead of calling both
await beforeAddUserToRoomPatch([userToBeAdded.username!], room, inviterUser);
await beforeAddUserToRoom.run({ user: userToBeAdded, inviter: inviterUser }, room);
} catch (error) {
throw new Meteor.Error((error as any)?.message);
}
View on GitHub (pinned to b2c16d5842)
Solutions
- Confirm the user exists (users.info API / Users.findOneById) before adding.
- Refresh the user picker or member cache.
- Filter deleted users out of bulk add lists.
Example fix
// before
await addUserToRoom(rid, user); // throws 'user-not-found'
// after
const exists = await Users.findOneById(user._id, { projection: { _id: 1 } });
if (exists) {
await addUserToRoom(rid, user);
} Defensive patterns
Strategy: validation
Validate before calling
const exists = await Users.findOneById(user._id, { projection: { _id: 1 } });
if (!exists) {
// skip adding a deleted user
} Try / catch
try {
await addUserToRoom(rid, user, inviter);
} catch (error: any) {
if (error?.error === 'user-not-found') {
// filter this user out of the member list and continue
}
} Prevention
- Filter deleted users from member pickers and bulk imports.
- Note the code has no 'error-' prefix - match on 'user-not-found' exactly.
- Refresh user data before bulk membership operations.
When it happens
Trigger: Adding a deleted user to a room: stale member picker, user deleted between selection and submission, bulk-add lists with stale ids.
Common situations: Deleted users still shown in an outdated user picker; import scripts referencing missing users; races with user deletion.
Related errors
- error-invalid-user
- error-invalid-user
- Only channels, private groups and direct messages can be cre
- Invalid user
- error-invalid-room
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/f5a2f8b144ad112c.
Report an issue: GitHub.