RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

executeUnarchiveRoom loads the user and requires isRegisterUser — a guard from @rocket.chat/core-typings that demands both username and name be defined on the user document. The call throws error-invalid-user when the record is missing or lacks those fields. Note the error detail names method 'archiveRoom': a copy-paste artifact from the sibling method; the failing call is unarchiveRoom.

Source

Thrown at apps/meteor/server/meteor-methods/rooms/unarchiveRoom.ts:23

import { Meteor } from 'meteor/meteor';

import { hasPermissionAsync } from '../../lib/authorization/hasPermission';
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
import { unarchiveRoom } from '../../lib/rooms/unarchiveRoom';

declare module '@rocket.chat/ddp-client' {
	// eslint-disable-next-line @typescript-eslint/naming-convention
	interface ServerMethods {
		unarchiveRoom(rid: string): Promise<void>;
	}
}

export const executeUnarchiveRoom = async (userId: string, rid: string) => {
	check(rid, String);

	const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });
	if (!user || !isRegisterUser(user)) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });
	}

	const room = await Rooms.findOneById(rid);

	if (!room) {
		throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'unarchiveRoom' });
	}

	if (!(await hasPermissionAsync(userId, 'unarchive-room', room._id))) {
		throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'unarchiveRoom' });
	}

	return unarchiveRoom(rid, user);
};

Meteor.methods<ServerMethods>({
	async unarchiveRoom(rid) {
		methodDeprecationLogger.method('unarchiveRoom', '9.0.0', '/v1/channels.unarchive');

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Run unarchiveRoom as a fully provisioned user whose record has both username and name
  2. Fix the user document (set the missing name) or switch to a proper admin account
  3. Validate the acting user server-side (findOneById + isRegisterUser) before invoking executeUnarchiveRoom
  4. Do not route on the misleading 'archiveRoom' string in the error details

Example fix

// before
await executeUnarchiveRoom(botUserId, rid); // bot user has no `name` field

// after
const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });
if (!user || !isRegisterUser(user)) throw new Meteor.Error('error-invalid-user', 'Invalid user');
await executeUnarchiveRoom(user._id, rid);
Defensive patterns

Strategy: validation

Validate before calling

import { isRegisterUser } from '@rocket.chat/core-typings';

const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });
if (!user || !isRegisterUser(user)) {
  // pick a fully provisioned user (username AND name set) before calling unarchiveRoom
}

Type guard

// server-side, after the projection load
const isValidActor = (u: { username?: string; name?: string } | null): u is { username: string; name: string } =>
  !!u && u.username !== undefined && u.name !== undefined;

Try / catch

try {
  await Meteor.callAsync('unarchiveRoom', rid);
} catch (error) {
  if (error instanceof Meteor.Error && error.error === 'error-invalid-user') {
    // acting user missing or incomplete (no username/name): switch to a real admin account
  }
}

Prevention

When it happens

Trigger: Unarchiving with a userId whose Users document was deleted, or whose document has no username or no name (incomplete provisioning, some bot/app accounts); server-side invocation with a fabricated id.

Common situations: Bot or app accounts without a populated name field used for moderation actions; users mid-provisioning; partial user records created by a faulty import.

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/67d7ef94e8607842. Report an issue: GitHub.