RocketChat/Rocket.Chat · error · Error

error-invalid-user

error-invalid-user

Error message

error-invalid-user

What it means

setSLAToInquiry requires userId to resolve a user document that has a username (Users.findOneById with username projected). A deleted user, a malformed id, or a user record lacking username throws 'error-invalid-user'.

Solutions

  1. Re-authenticate and pass the current acting user's id
  2. Verify the user with Users.findOneById before the call
  3. If the user was deleted, route the SLA change through another agent
Defensive patterns

Strategy: validation

Validate before calling

import { Users } from '@rocket.chat/models';

const user = await Users.findOneById(userId, { projection: { username: 1 } });
if (!user?.username) {
  throw new Error(`acting user ${userId} does not exist or has no username`);
}
await setSLAToInquiry({ userId, roomId, sla });

Try / catch

try {
  await setSLAToInquiry({ userId, roomId, sla });
} catch (error) {
  if (error instanceof Error && error.message === 'error-invalid-user') {
    throw new NotFoundError(`acting user ${userId} was deleted or is invalid - re-authenticate`);
  }
  throw error;
}

Prevention

When it happens

Trigger: userId from a stale session/PAT of a deleted user; a truncated or malformed id; user document without the username field (edge-case import).

Common situations: Tokens outliving their accounts; ids copied between environments (dev vs prod); automation storing user ids past user deletion.

Understand the failure class

Background: "User not found", "Invalid user", and "does not exist": what missing-user lookup errors mean across Rocket.Chat, LiteLLM, Phabricator, rustfs, and pnpm — this error's family across 10 libraries.

Related errors


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

Appendix: source

Thrown at apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts:18

import { LivechatInquiry, Users, OmnichannelServiceLevelAgreements } from '@rocket.chat/models';

import { updateRoomSLA } from './sla';

export async function setSLAToInquiry({ userId, roomId, sla }: { userId: string; roomId: string; sla?: string }): Promise<void> {
	const inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });
	if (!inquiry || inquiry.status !== 'queued') {
		throw new Error('error-invalid-inquiry');
	}

	const slaData = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));
	if (!slaData) {
		throw new Error('error-invalid-sla');
	}

	const user = await Users.findOneById(userId, { projection: { _id: 1, username: 1, name: 1 } });
	if (!user?.username) {
		throw new Error('error-invalid-user');
	}

	await updateRoomSLA(
		roomId,
		{
			_id: user._id,
			name: user.name || '',
			username: user.username,
		},
		slaData,
	);
}

View on GitHub (pinned to b2c16d5842)