RocketChat/Rocket.Chat · error · Error

error-invalid-user

error-invalid-user

Error message

error-invalid-user

What it means

The moderation helper reportMessage throws plain Error('error-invalid-user') when its uid argument is falsy - no reporting user id was supplied. It is an argument-integrity guard that fires before any lookup; the same code is thrown again further down when Users.findOneById(uid) finds nothing.

Source

Thrown at apps/meteor/server/lib/moderation/reportMessage.ts:9

import { Apps, AppEvents } from '@rocket.chat/apps';
import type { IMessage, IUser } from '@rocket.chat/core-typings';
import { Messages, ModerationReports, Rooms, Users } from '@rocket.chat/models';

import { canAccessRoomAsync } from '../authorization/canAccessRoom';

export const reportMessage = async (messageId: IMessage['_id'], description: string, uid: IUser['_id']) => {
	if (!uid) {
		throw new Error('error-invalid-user');
	}

	if (!description.trim()) {
		throw new Error('error-invalid-description');
	}

	const message = await Messages.findOneById(messageId);

	if (!message) {
		throw new Error('error-invalid-message_id');
	}

	const user = await Users.findOneById(uid);

	if (!user) {
		throw new Error('error-invalid-user');
	}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Resolve and pass a real user id (Meteor.userId() or the app's acting user) before calling
  2. Validate uid is a non-empty string at the call boundary
  3. Pre-check Users.findOneById(uid) to also avoid the sibling user-not-found throw

Example fix

// before
await reportMessage(messageId, description, uid); // uid undefined

// after
const uid = this.userId ?? appUser?._id;
if (!uid) throw new Meteor.Error('error-invalid-user');
await reportMessage(messageId, description, uid);
Defensive patterns

Strategy: type-guard

Validate before calling

const uid = Meteor.userId();
if (typeof uid === 'string' && uid.length > 0) {
  await reportMessage(messageId, description, uid);
} else {
  return requireAuthentication();
}

Type guard

const isNonEmptyUserId = (uid: unknown): uid is string =>
  typeof uid === 'string' && uid.length > 0;

Try / catch

try {
  await reportMessage(messageId, description, uid);
} catch (e) {
  if (e instanceof Error && e.message === 'error-invalid-user') {
    // resolve a valid acting user before retrying; never retry with the same empty uid
  }
}

Prevention

When it happens

Trigger: Server code or apps calling reportMessage(messageId, description, uid) with an empty/undefined uid - typically using a connection without this.userId and never resolving an acting user first.

Common situations: Apps Engine handlers that forget to pass the acting user; server code calling the helper with a session that has no bound user; refactors dropping the uid parameter.

Understand the failure class

Background: error-invalid-user: "Invalid user" errors in Rocket.Chat — what they mean and how to fix them — this error's family across 2 libraries.

Related errors


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