RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

createRoom throws error-invalid-user (with function RocketChat.createRoom) when the owner argument is falsy — no user document/object was supplied as the room creator. The owner drives subscription creation and must exist.

Source

Thrown at apps/meteor/server/lib/rooms/createRoom.ts:211

	}

	const memberList = [...members];

	if (!onlyUsernames(memberList)) {
		throw new Meteor.Error(
			'error-invalid-members',
			'members should be an array of usernames if provided for rooms other than direct messages',
		);
	}

	if (!isValidName(name)) {
		throw new Meteor.Error('error-invalid-name', 'Invalid name', {
			function: 'RocketChat.createRoom',
		});
	}

	if (!owner) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', {
			function: 'RocketChat.createRoom',
		});
	}

	if (!owner?.username) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', {
			function: 'RocketChat.createRoom',
		});
	}

	if (!excludeSelf && owner.username && !memberList.includes(owner.username)) {
		memberList.push(owner.username);
	}

	if (extraData.broadcast) {
		readOnly = true;
		delete extraData.reactWhenReadOnly;
	}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Verify the owner exists before creating the room: const owner = await Users.findOneByUsername(username); if (!owner) throw ...
  2. If the user was deleted, restore it or pick another owner
  3. Log the resolved owner id/username right before createRoom in your integration to catch pass-through nulls

Example fix

// before
createRoom('c', name, await Users.findOneByUsername(username), members, extraData);

// after
const owner = await Users.findOneByUsername(username);
if (!owner) throw new Meteor.Error('error-invalid-user', `Owner ${username} not found`);
createRoom('c', name, owner, members, extraData);
Defensive patterns

Strategy: type-guard

Validate before calling

const owner = await Users.findOneByUsername(ownerUsername);
if (!owner) {
  throw new Meteor.Error('error-invalid-user', `Owner ${ownerUsername} not found`);
}
await createRoom(type, name, owner, members, extraData);

Type guard

const isExistingOwner = (owner: unknown): owner is IUser =>
  Boolean(owner && typeof owner === 'object' && '_id' in owner);

Try / catch

try {
  await createRoom(type, name, owner, members, extraData);
} catch (err) {
  if (err instanceof Meteor.Error && err.error === 'error-invalid-user') {
    // re-resolve the owner by username, verify existence, then retry
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling createRoom with owner = null/undefined — typically because a Users.findOneByUsername lookup earlier in the call chain returned null (user not found) and was passed through unchecked.

Common situations: Creating rooms on behalf of a username that does not exist (typo, deleted user, or bot user not yet provisioned); importers or scripts that resolve the owner by username and skip the null check.

Related errors


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