RocketChat/Rocket.Chat · error · Meteor.Error

error-message-not-found

error-message-not-found

Error message

The provided "messageId" does not match any existing message.

What it means

Thrown by the chat.pinMessage endpoint when Messages.findOneById(this.bodyParams.messageId) returns null. The messageId was parsed from the body but no message with that _id exists. Uses Meteor.Error code 'error-message-not-found'.

Source

Thrown at apps/meteor/server/api/v1/chat.ts:213

				200: ajv.compile<{ message: IMessage }>({
					type: 'object',
					properties: {
						message: { $ref: '#/components/schemas/IMessage' },
						success: {
							type: 'boolean',
							enum: [true],
						},
					},
					required: ['message', 'success'],
					additionalProperties: false,
				}),
			},
		},
		async function action() {
			const msg = await Messages.findOneById(this.bodyParams.messageId);

			if (!msg) {
				throw new Meteor.Error('error-message-not-found', 'The provided "messageId" does not match any existing message.');
			}

			const pinnedMessage = await pinMessage(msg, this.userId);

			const [message] = await normalizeMessagesForUser([pinnedMessage], this.userId);

			return API.v1.success({
				message,
			});
		},
	)
	.post(
		'chat.unPinMessage',
		{
			authRequired: true,
			body: isChatUnpinMessageProps,
			response: {
				400: validateBadRequestErrorResponse,

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Verify the messageId exists (e.g., via chat.getMessage) before pinning.
  2. Refresh the message context and discard ids for messages that no longer load.
  3. Handle error-message-not-found in the client by removing the pin option from deleted messages.

Example fix

// before
await fetch('/api/v1/chat.pinMessage', { method: 'POST', body: JSON.stringify({ messageId }) });

// after
const exists = await fetchMessage(messageId);
if (!exists) {
  notifyUser('Message no longer exists');
  return;
}
await fetch('/api/v1/chat.pinMessage', { method: 'POST', body: JSON.stringify({ messageId }) });
Defensive patterns

Strategy: validation

Validate before calling

async function pinIfExists(messageId, userId) {
  const msg = await Messages.findOneById(messageId);
  if (!msg) throw new Error('message-not-found');
  return pinMessage(msg, userId);
}

Type guard

function isExistingMessage(msg) {
  return Boolean(msg) && typeof msg._id === 'string' && typeof msg.rid === 'string';
}

Try / catch

try {
  await api.pinMessage({ messageId });
} catch (e) {
  if (e.error === 'error-message-not-found') {
    removeMessageFromUI(messageId); // stale id
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: POST chat.pinMessage with a messageId that does not correspond to any message document (deleted, typo, wrong workspace).

Common situations: Pinning a message that was deleted between render and click; messageId copied from another server; client cache holding a stale id.

Related errors


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