RocketChat/Rocket.Chat · error · Error

invalid-parameter

Error message

invalid-parameter

What it means

Thrown by getPermaLink when the msgId argument is falsy (empty string, null, undefined, 0, false). getPermaLink constructs a permanent URL to a specific message and requires a non-empty message ID. This is a parameter validation guard at the top of the function, before any store or API access.

Source

Thrown at apps/meteor/client/lib/getPermaLink.ts:17

import type { IMessage, Serialized } from '@rocket.chat/core-typings';

import { getUserId } from './user';

const getMessage = async (msgId: string): Promise<Serialized<IMessage> | null> => {
	try {
		const { sdk } = await import('../../app/utils/client/lib/SDKClient');
		const { message } = await sdk.rest.get('/v1/chat.getMessage', { msgId });
		return message;
	} catch {
		return null;
	}
};

export const getPermaLink = async (msgId: string): Promise<string> => {
	if (!msgId) {
		throw new Error('invalid-parameter');
	}

	const { Messages, Rooms, Subscriptions } = await import('../stores');

	const msg = Messages.state.get(msgId) || (await getMessage(msgId));
	if (!msg) {
		throw new Error('message-not-found');
	}
	const roomData = Rooms.state.get(msg.rid);

	if (!roomData) {
		throw new Error('room-not-found');
	}

	const subData = Subscriptions.state.find((record) => record.rid === roomData._id && record.u._id === getUserId());

	const { roomCoordinator } = await import('./rooms/roomCoordinator');

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Validate msgId is a non-empty string before calling getPermaLink.
  2. Ensure the message object is fully loaded (has _id) before extracting and passing the ID.
  3. Disable or hide the 'copy permalink' UI control until the message ID is available.
  4. Use optional chaining or early-return in the caller if msgId may be absent.

Example fix

// before
const link = await getPermaLink(msg?._id);
// after
if (!msg?._id) return;
const link = await getPermaLink(msg._id);
Defensive patterns

Strategy: validation

Validate before calling

if (!msgId || typeof msgId !== 'string' || msgId.trim() === '') {
  throw new Error('msgId is required');
}
const link = await getPermaLink(msgId);

Type guard

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

Try / catch

try {
  const link = await getPermaLink(msgId);
} catch (e) {
  if (e instanceof Error && e.message === 'invalid-parameter') {
    // msgId was empty or missing
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Code calls getPermaLink('') or getPermaLink(undefined). A UI component passes an uninitialised message ID state variable. A message object without an _id is used to extract the ID. Dynamic import path resolves to a message whose ID extraction yields an empty string.

Common situations: Context menu 'copy link' triggered before message data is fully loaded. Message reference from a deleted or pending message that has no _id yet. Programmatic call with a variable that hasn't been assigned. Race condition where the ID is read before the message object is set.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/9570f7728b33963f. Report an issue: GitHub.