{"record":{"id":"f9224adc85f6cd61","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-description","errorCode":"error-invalid-description","errorMessage":"error-invalid-description","messagePattern":"error-invalid-description","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/lib/moderation/reportMessage.ts","lineNumber":13,"sourceCode":"import { Apps, AppEvents } from '@rocket.chat/apps';\nimport type { IMessage, IUser } from '@rocket.chat/core-typings';\nimport { Messages, ModerationReports, Rooms, Users } from '@rocket.chat/models';\n\nimport { canAccessRoomAsync } from '../authorization/canAccessRoom';\n\nexport const reportMessage = async (messageId: IMessage['_id'], description: string, uid: IUser['_id']) => {\n\tif (!uid) {\n\t\tthrow new Error('error-invalid-user');\n\t}\n\n\tif (!description.trim()) {\n\t\tthrow new Error('error-invalid-description');\n\t}\n\n\tconst message = await Messages.findOneById(messageId);\n\n\tif (!message) {\n\t\tthrow new Error('error-invalid-message_id');\n\t}\n\n\tconst user = await Users.findOneById(uid);\n\n\tif (!user) {\n\t\tthrow new Error('error-invalid-user');\n\t}\n\n\tconst { rid } = message;\n\t// If the user can't access the room where the message is, report that the message id is invalid\n\tconst room = await Rooms.findOneById(rid);\n\tif (!room || !(await canAccessRoomAsync(room, { _id: uid }))) {","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/moderation/reportMessage.ts#L1-L31","documentation":"reportMessage requires a non-blank reason: description.trim() must be truthy, otherwise it throws plain Error('error-invalid-description'). Moderation reports must carry report text, so empty or whitespace-only descriptions are rejected before the message is even looked up.","triggerScenarios":"reportMessage(msgId, '', uid) or a whitespace-only description: the client submitted the report dialog without text, or an integration sent no reason.","commonSituations":"Report UI with an optional-looking message box; automated abuse-report scripts sending empty descriptions; users entering only spaces to bypass the dialog.","solutions":["Require non-empty report text in the UI and disable submit until filled","Trim and length-check the description client-side before calling","In integrations, default to a meaningful reason string instead of sending blank"],"exampleFix":"// before\nawait reportMessage(messageId, '   ', uid); // whitespace-only\n\n// after\nconst reason = description.trim();\nif (!reason) return focusReportTextarea();\nawait reportMessage(messageId, reason, uid);","handlingStrategy":"validation","validationCode":"const reason = description.trim();\nif (reason.length > 0) {\n  await reportMessage(messageId, reason, uid);\n} else {\n  return requireReportText();\n}","typeGuard":"const hasReportText = (description: string): boolean =>\n  typeof description === 'string' && description.trim().length > 0;","tryCatchPattern":"try {\n  await reportMessage(messageId, description, uid);\n} catch (e) {\n  if (e instanceof Error && e.message === 'error-invalid-description') {\n    focusReportTextarea(); // keep the dialog open and ask for a reason\n  }\n}","preventionTips":["Make the report reason required in the UI and disable submit until filled","Trim input client-side before sending","Give integrations a sensible default reason instead of sending blank text"],"tags":["moderation","reporting","validation"],"backgroundTag":"missing-required-argument","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"}