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

  1. Confirm the user exists (users.info API / Users.findOneById) before adding.
  2. Refresh the user picker or member cache.
  3. 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

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


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