RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The exported server-side sendFileMessage(userId, { roomId, file, msgData }) helper loads the sender with Users.findOneById(userId) and throws error-invalid-user when the record is missing. This is the internal variant used by REST handlers, apps and integrations, so the id arrives as a parameter rather than from the DDP connection.

Source

Thrown at apps/meteor/server/meteor-methods/messages/sendFileMessage.ts:188

	}
}

export const sendFileMessage = async (
	userId: string,
	{
		roomId,
		file,
		msgData,
	}: {
		roomId: string;
		file: Partial<IUpload>;
		msgData?: Record<string, any>;
	},
): Promise<boolean> => {
	const user = await Users.findOneById(userId, { projection: { services: 0 } });

	if (!user) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', {
			method: 'sendFileMessage',
		} as any);
	}

	const room = await Rooms.findOneById(roomId);
	if (!room) {
		return false;
	}

	if (user?.type !== 'app' && !(await canAccessRoomAsync(room, user))) {
		return false;
	}

	check(
		msgData,
		Match.Maybe({
			avatar: Match.Optional(String),
			emoji: Match.Optional(String),

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Verify the user exists before invoking the helper server-side
  2. Check the argument order: sendFileMessage(userId, { roomId, file, msgData })
  3. If the sender was deleted, drop the request instead of retrying - it will never succeed
Defensive patterns

Strategy: validation

Validate before calling

// server-side caller: verify the sender before sending
import { Users } from '@rocket.chat/models';

const user = await Users.findOneById(userId, { projection: { username: 1 } });
if (!user?.username) {
	throw new Error(`sender ${userId} does not exist`);
}
return sendFileMessage(userId, { roomId, file, msgData });

Prevention

When it happens

Trigger: Passing a userId that was deleted between request start and processing; an apps-engine or REST handler forwarding a stale uid; swapped arguments (e.g. passing roomId where userId is expected); typo'd or truncated user id.

Common situations: Offboarding deletes a user while a queued bot job still references them; migration scripts with dirty user data; custom integration constructing the call with the wrong variable order.

Related errors


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