RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-name

error-invalid-name

Error message

Invalid name

What it means

createRoom validates the room name with isValidName (must be a non-empty string after trim). A non-string, empty, or whitespace-only name triggers error-invalid-name with function RocketChat.createRoom in the error details.

Source

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

			method: 'createRoom',
		});
	}

	if (type === 'd') {
		return createDirectRoom(members as IUser[], extraData, { ...options, creator: options?.creator || owner?._id });
	}

	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);

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Default or validate the name before calling createRoom: name?.trim() && name or throw a user-facing error early
  2. Check argument order in the call signature (type, name, owner, members, extraData)
  3. Sanitize upstream input (REST endpoint / method param) with the same trim + non-empty rule

Example fix

// before
createRoom('c', userInput.name, owner, members, extraData);

// after
const name = userInput.name?.trim();
if (!name) throw new Meteor.Error('error-invalid-name', 'Invalid name');
createRoom('c', name, owner, members, extraData);
Defensive patterns

Strategy: validation

Validate before calling

const name = typeof rawName === 'string' ? rawName.trim() : '';
if (!name) {
  throw new Meteor.Error('error-invalid-name', 'Room name is required');
}
await createRoom(type, name, owner, members, extraData);

Type guard

const isValidName = (name: unknown): name is string =>
  typeof name === 'string' && name.trim().length > 0;

Try / catch

try {
  await createRoom(type, name, owner, members, extraData);
} catch (err) {
  if (err instanceof Meteor.Error && err.error === 'error-invalid-name') {
    // prompt the user for a valid name
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling createRoom with name = '', ' ', undefined, null, or a non-string value (number, object). Only applies to non-DM rooms since type 'd' returns early to createDirectRoom.

Common situations: Dynamic room creation where the name comes from user input or a template that rendered empty; passing the room name positionally and accidentally swapping arguments; team/discussion creation flows where the parent name was never resolved.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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