{"record":{"id":"be94cc82fc249b5a","repo":"RocketChat/Rocket.Chat","slug":"invalid-payload","errorCode":null,"errorMessage":"Invalid payload","messagePattern":"Invalid payload","errorType":"exception","errorClass":"Error","httpStatus":500,"severity":"error","filePath":"apps/meteor/server/modules/core-apps/mention.module.ts","lineNumber":16,"sourceCode":"import { api } from '@rocket.chat/core-services';\nimport type { IUiKitCoreApp, UiKitCoreAppBlockActionPayload } from '@rocket.chat/core-services';\nimport type { IMessage, IUser } from '@rocket.chat/core-typings';\nimport { Subscriptions, Messages } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { i18n } from '../../lib/i18n';\nimport { processWebhookMessage } from '../../lib/messages/processWebhookMessage';\nimport { roomCoordinator } from '../../lib/rooms/roomCoordinator';\nimport { addUsersToRoomMethod } from '../../meteor-methods/rooms/addUsersToRoom';\n\nconst retrieveMentionsFromPayload = (stringifiedMentions: string): Exclude<IMessage['mentions'], undefined> => {\n\ttry {\n\t\tconst mentions = JSON.parse(stringifiedMentions);\n\t\tif (!Array.isArray(mentions) || !mentions.length || !('username' in mentions[0])) {\n\t\t\tthrow new Error('Invalid payload');\n\t\t}\n\t\treturn mentions;\n\t} catch (error) {\n\t\tthrow new Error('Invalid payload');\n\t}\n};\n\nexport class MentionModule implements IUiKitCoreApp {\n\tappId = 'mention-core';\n\n\tasync blockAction(payload: UiKitCoreAppBlockActionPayload): Promise<undefined> {\n\t\tconst {\n\t\t\tactionId,\n\t\t\tpayload: { value: stringifiedMentions, blockId: referenceMessageId },\n\t\t} = payload;\n\n\t\tconst user = payload.user!;\n\t\tconst room = payload.room!;","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/modules/core-apps/mention.module.ts#L1-L34","documentation":"`retrieveMentionsFromPayload` in the `mention-core` UiKit core app parses the block action's `value` (a JSON-stringified mentions array). After a successful `JSON.parse`, it validates the result: it must be a non-empty array whose first element has a `username` property. Failing that shape check throws `Error('Invalid payload')` at this line.","triggerScenarios":"A mention-core blockAction where `payload.value` parses as JSON but is not a mentions array — e.g. `[\"user1\"]` (strings instead of objects), `[]` (empty), `{}` (not an array), or objects lacking `username` like `[{ _id: 'x' }]`.","commonSituations":"Custom clients building the mention prompt value by hand; payload shapes changed between versions; double-stringified or truncated JSON that happens to parse to a non-array value.","solutions":["Send the value as `JSON.stringify(mentions)` where mentions is `[{ username: 'user1' }, ...]` — non-empty, each entry with a `username` field.","Check the raw `value` string before dispatch to confirm it parses to the expected array-of-username-objects shape.","If you build the ephemeral mention prompt yourself, reuse the same serialization as the core mention bot."],"exampleFix":"// before\nvalue: JSON.stringify(['user1', 'user2'])\n\n// after\nvalue: JSON.stringify([{ username: 'user1' }, { username: 'user2' }])","handlingStrategy":"validation","validationCode":"const isMentionArray = (value: unknown): value is { username: string }[] =>\n  Array.isArray(value) && value.length > 0 && value.every((m) => typeof m === 'object' && m !== null && 'username' in m);\n\nconst parsed = JSON.parse(stringifiedMentions);\nif (!isMentionArray(parsed)) {\n  throw new Error('Mentions value must be a non-empty array of { username } objects');\n}\n// safe to dispatch","typeGuard":"type Mention = { username: string };\n\nfunction isMentionArray(value: unknown): value is Mention[] {\n  return (\n    Array.isArray(value) &&\n    value.length > 0 &&\n    value.every((m) => typeof m === 'object' && m !== null && typeof (m as Mention).username === 'string')\n  );\n}","tryCatchPattern":"try {\n  await mentionModule.blockAction(payload);\n} catch (error) {\n  if (error instanceof Error && error.message === 'Invalid payload') {\n    // log payload.payload.value to inspect the malformed mentions JSON\n  }\n}","preventionTips":["Serialize mentions with JSON.stringify([{ username }])","Validate the parsed shape before dispatch","Add unit tests for the mention value format"],"tags":["uikit","mentions","payload-validation","json"],"backgroundTag":"invalid-json-payload","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}