RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-message

error-invalid-message

Error message

Invalid message

What it means

followMessage resolves the id via Messages.findOneById(mid); when no message matches it throws 'error-invalid-message'. The message may never have existed, or may have been deleted or purged between the client rendering a follow affordance and the call landing on the server.

Source

Thrown at apps/meteor/server/meteor-methods/messages/followMessage.ts:29

import { follow } from '../../lib/messaging/threads/functions';
import { notifyOnMessageChange } from '../../lib/notifyListener';
import { settings } from '../../settings';

declare module '@rocket.chat/ddp-client' {
	// eslint-disable-next-line @typescript-eslint/naming-convention
	interface ServerMethods {
		followMessage(message: { mid: IMessage['_id'] }): false | undefined;
	}
}

export const followMessage = async (user: IUser, { mid }: { mid: IMessage['_id'] }): Promise<false | undefined> => {
	if (mid && !settings.get('Threads_enabled')) {
		throw new Meteor.Error('error-not-allowed', 'not-allowed', { method: 'followMessage' });
	}

	const message = await Messages.findOneById(mid);
	if (!message) {
		throw new Meteor.Error('error-invalid-message', 'Invalid message', {
			method: 'followMessage',
		});
	}

	if (!(await canAccessRoomIdAsync(message.rid, user._id))) {
		throw new Meteor.Error('error-not-allowed', 'not-allowed', { method: 'followMessage' });
	}

	const id = message.tmid || message._id;

	const followResult = await follow({ tmid: id, uid: user._id });

	void notifyOnMessageChange({
		id,
	});

	const isFollowed = true;
	await Apps.self?.triggerEvent(AppEvents.IPostMessageFollowed, message, user, isFollowed);

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Only offer follow for messages from a live, fresh message payload (current subscription data)
  2. Handle 'error-invalid-message' by refreshing the thread state and hiding the follow affordance
  3. For deep links, verify the message still exists (jump-to-message) before exposing follow

Example fix

// before
await Meteor.callAsync('followMessage', { mid });

// after
try {
  await Meteor.callAsync('followMessage', { mid });
} catch (e) {
  if (e.error === 'error-invalid-message') {
    // message gone: drop it from local cache, stop offering follow
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

const message = Messages.findOne({ _id: mid }); // local cache check
if (!message) {
  // do not offer follow for messages not in the current store
}
Meteor.call('followMessage', { mid });

Try / catch

try {
  await Meteor.callAsync('followMessage', { mid });
} catch (e) {
  if ((e as Meteor.Error).error === 'error-invalid-message') {
    // message deleted concurrently: purge from cache, hide follow
  }
}

Prevention

When it happens

Trigger: Meteor.call('followMessage', { mid }) with a mistyped id, the id of a deleted message, or a race where retention/purge removed the message after render.

Common situations: Follow buttons rendered from stale message lists; message-retention policies purging old messages; ids corrupted or truncated in deep links.

Related errors


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