RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-command-preview

error-invalid-command-preview

Error message

Invalid Preview Provided

What it means

executeSlashCommandPreview requires a preview: SlashCommandPreviewItem as its second argument; a falsy value throws 'error-invalid-command-preview'. The item identifies which preview option the user picked (id/type/value), so without it the server cannot know what to execute.

Source

Thrown at apps/meteor/server/meteor-methods/messages/executeSlashCommandPreview.ts:46

	},
	preview: SlashCommandPreviewItem,
	userId: string,
): Promise<void> => {
	if (!command?.cmd || !slashCommands.commands[command.cmd]) {
		throw new Meteor.Error('error-invalid-command', 'Invalid Command Provided', {
			method: 'executeSlashCommandPreview',
		});
	}

	const theCmd = slashCommands.commands[command.cmd];
	if (!theCmd.providesPreview) {
		throw new Meteor.Error('error-invalid-command', 'Command Does Not Provide Previews', {
			method: 'executeSlashCommandPreview',
		});
	}

	if (!preview) {
		throw new Meteor.Error('error-invalid-command-preview', 'Invalid Preview Provided', {
			method: 'executeSlashCommandPreview',
		});
	}

	return slashCommands.executePreview(command.cmd, command.params, command.msg, preview, userId, command.triggerId);
};

Meteor.methods<ServerMethods>({
	executeSlashCommandPreview(command, preview) {
		const userId = Meteor.userId();
		if (!userId) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'getSlashCommandPreview',
			});
		}

		return executeSlashCommandPreview(command, preview, userId);
	},

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Construct and pass a SlashCommandPreviewItem ({ id, type, value }) sourced from the preview list the user selected
  2. Keep the execute action disabled until a preview option is actually selected
  3. Validate the preview object's shape before invoking the method

Example fix

// before
Meteor.call('executeSlashCommandPreview', cmd, selected /* possibly undefined */);

// after
if (!selected?.id) {
  return; // nothing chosen yet
}
Meteor.call('executeSlashCommandPreview', cmd, selected);
Defensive patterns

Strategy: validation

Validate before calling

if (!preview || !preview.id || !preview.type) {
  // nothing selected yet: keep the execute action disabled
  return;
}
Meteor.call('executeSlashCommandPreview', command, preview);

Type guard

const isPreviewItem = (p: unknown): p is { id: string; type: string; value: string } =>
  typeof p === 'object' && p !== null && 'id' in p && 'type' in p && 'value' in p;

Prevention

When it happens

Trigger: Meteor.call('executeSlashCommandPreview', command, null) — a handler wiring a button that forgot to forward the selected item, or destructuring that yields undefined because no option was chosen yet.

Common situations: Click handlers firing before a selection exists; refactors renaming the preview item fields; races where the preview list was empty and the selected item is undefined.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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