{"record":{"id":"6e14d176030031ad","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-preview","errorCode":"error-invalid-preview","errorMessage":"Preview Item must have an id, type, and value.","messagePattern":"Preview Item must have an id, type, and value\\.","errorType":"exception","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/utils/slashCommand.ts","lineNumber":128,"sourceCode":"\t\tcommand: string,\n\t\tparams: string,\n\t\tmessage: Pick<IMessage, 'rid'> & Partial<Omit<IMessage, 'rid'>>,\n\t\tpreview: SlashCommandPreviewItem,\n\t\tuserId: string,\n\t\ttriggerId?: string,\n\t) {\n\t\tconst cmd = this.commands[command];\n\t\tif (typeof cmd?.previewCallback !== 'function') {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!message?.rid) {\n\t\t\tthrow new MeteorError('invalid-command-usage', 'Executing a command requires at least a message with a room id.');\n\t\t}\n\n\t\t// { id, type, value }\n\t\tif (!preview.id || !preview.type || !preview.value) {\n\t\t\tthrow new MeteorError('error-invalid-preview', 'Preview Item must have an id, type, and value.');\n\t\t}\n\n\t\treturn cmd.previewCallback(command, params, message, preview, userId, triggerId);\n\t},\n};\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tslashCommand(params: { cmd: string; params: string; msg: IMessage; triggerId: string }): unknown;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync slashCommand(command) {\n\t\tmethodDeprecationLogger.method('slashCommand', '9.0.0', '/v1/commands.run');\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/utils/slashCommand.ts#L110-L146","documentation":"executePreviewResponse() validates the selected SlashCommandPreviewItem before delegating to the command's previewCallback: it must be a complete { id, type, value } triple. This protects command implementations from acting on half-built items. The check is truthiness-based, so empty strings in any of the three fields also trigger it.","triggerScenarios":"executePreviewResponse invoked with a preview item like { id: '1', type: 'image' } (no value) or any field as '' ; client code synthesizing a slimmer item object instead of passing back exactly what getPreviews returned; serialization round-trips that drop falsy values.","commonSituations":"UI state mapping preview items to { id } only; JSON/DDP transport dropping fields; refactors of the command palette payload shape.","solutions":["Pass the exact SlashCommandPreviewItem object received from getPreviews back into executePreviewResponse.","If you must rebuild items, populate all three fields with non-empty values.","Validate the item shape at the boundary when previews cross serialization layers."],"exampleFix":"// before: rebuilt item lost 'value' -> error-invalid-preview\nawait slashCommands.executePreviewResponse('gimme', 'cat', msg, { id: item.id, type: item.type } as SlashCommandPreviewItem, userId);\n\n// after: send the full item from getPreviews()\nawait slashCommands.executePreviewResponse('gimme', 'cat', msg, item, userId);","handlingStrategy":"validation","validationCode":"// Mirror of the server-side truthiness check\nconst isValidPreviewItem = (p: SlashCommandPreviewItem): boolean =>\n  Boolean(p && p.id && p.type && p.value);","typeGuard":"const isCompletePreviewItem = (p: unknown): p is SlashCommandPreviewItem => {\n  const c = p as { id?: unknown; type?: unknown; value?: unknown } | null;\n  return Boolean(c && c.id && c.type && c.value);\n};","tryCatchPattern":"try {\n  await slashCommands.executePreviewResponse(cmd, params, message, preview, userId);\n} catch (err: any) {\n  if (err?.error === 'error-invalid-preview') {\n    // item shape lost in transit: refresh previews via getPreviews instead of retrying the stale item\n    return refreshPreviews(cmd, params, message, userId);\n  }\n  throw err;\n}","preventionTips":["Pass the exact objects returned by getPreviews() back into executePreviewResponse().","Re-validate item shape after any serialization boundary (JSON, DDP, IPC).","Remember empty strings fail the check, not just missing fields."],"tags":["slash-commands","preview-item","schema","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}