{"record":{"id":"aafc033e960df93c","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-aafc03","errorCode":"error-invalid-user","errorMessage":"error-invalid-user","messagePattern":"error-invalid-user","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/lib/moderation/reportMessage.ts","lineNumber":9,"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","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/moderation/reportMessage.ts#L1-L27","documentation":"The moderation helper reportMessage throws plain Error('error-invalid-user') when its uid argument is falsy - no reporting user id was supplied. It is an argument-integrity guard that fires before any lookup; the same code is thrown again further down when Users.findOneById(uid) finds nothing.","triggerScenarios":"Server code or apps calling reportMessage(messageId, description, uid) with an empty/undefined uid - typically using a connection without this.userId and never resolving an acting user first.","commonSituations":"Apps Engine handlers that forget to pass the acting user; server code calling the helper with a session that has no bound user; refactors dropping the uid parameter.","solutions":["Resolve and pass a real user id (Meteor.userId() or the app's acting user) before calling","Validate uid is a non-empty string at the call boundary","Pre-check Users.findOneById(uid) to also avoid the sibling user-not-found throw"],"exampleFix":"// before\nawait reportMessage(messageId, description, uid); // uid undefined\n\n// after\nconst uid = this.userId ?? appUser?._id;\nif (!uid) throw new Meteor.Error('error-invalid-user');\nawait reportMessage(messageId, description, uid);","handlingStrategy":"type-guard","validationCode":"const uid = Meteor.userId();\nif (typeof uid === 'string' && uid.length > 0) {\n  await reportMessage(messageId, description, uid);\n} else {\n  return requireAuthentication();\n}","typeGuard":"const isNonEmptyUserId = (uid: unknown): uid is string =>\n  typeof uid === 'string' && uid.length > 0;","tryCatchPattern":"try {\n  await reportMessage(messageId, description, uid);\n} catch (e) {\n  if (e instanceof Error && e.message === 'error-invalid-user') {\n    // resolve a valid acting user before retrying; never retry with the same empty uid\n  }\n}","preventionTips":["Always derive uid from the session (this.userId) or a verified acting user","Type reportMessage call sites so uid cannot be omitted","Fail fast at the API boundary when authentication is missing"],"tags":["moderation","reporting","invalid-arguments"],"backgroundTag":"missing-user-id","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}