RocketChat/Rocket.Chat · error · Error
invalid-parameter
Error message
invalid-parameter
What it means
getPermaLink() throws 'invalid-parameter' as its very first guard when msgId is falsy (undefined, null, empty string) — before any store lookup or REST call. It exists because the function builds a URL with ?msg= and cannot do so meaningfully without an id.
Solutions
- Pass the message id explicitly: getPermaLink(message._id).
- Guard the call site: skip when the id is missing.
- Type the parameter as string and lint against passing objects.
Example fix
// before const link = await getPermaLink(message); // object → msgId undefined → throws // after const link = message._id ? await getPermaLink(message._id) : null;
Defensive patterns
Strategy: validation
Validate before calling
const id = typeof msgOrId === 'string' ? msgOrId : msgOrId?._id; if (!id) return; // never call getPermaLink without an id const url = await getPermaLink(id);
Type guard
const hasMessageId = (v: IMessage | string | undefined): v is string => typeof v === 'string' ? v.length > 0 : Boolean(v?._id);
Try / catch
try {
const url = await getPermaLink(msgId);
} catch (e) {
if (e instanceof Error && e.message === 'invalid-parameter') return; // caller bug: fix the id source
throw e;
} Prevention
- Always pass message._id, never the message object.
- Type the parameter as string so object misuse fails at compile time.
- Guard optional route/search params before invoking.
When it happens
Trigger: Calling getPermaLink(undefined), getPermaLink(''), or getPermaLink(null) — typically a caller passing a message object instead of its _id, or a route/search param that is absent.
Common situations: Copy-link handlers invoked before a message is selected; msgId destructured from an optional route param; refactors where the IMessage object was passed instead of message._id.
Related errors
- duplicated-account
- error-bio-size-exceeded
- error-bio-size-exceeded
- error-blocked-username
- error-business-hour-finish-time-before-start-time
AI-assisted analysis of RocketChat/Rocket.Chat@2f18297792 (2026-08-18).
Data as JSON: /api/errors/9570f7728b33963f.
Report an issue: GitHub.
Appendix: 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('./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 2f18297792)