{"record":{"id":"1e55e4d1d203f16e","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-1e55e4","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/messages/sendFileMessage.ts","lineNumber":188,"sourceCode":"\t}\n}\n\nexport const sendFileMessage = async (\n\tuserId: string,\n\t{\n\t\troomId,\n\t\tfile,\n\t\tmsgData,\n\t}: {\n\t\troomId: string;\n\t\tfile: Partial<IUpload>;\n\t\tmsgData?: Record<string, any>;\n\t},\n): Promise<boolean> => {\n\tconst user = await Users.findOneById(userId, { projection: { services: 0 } });\n\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'sendFileMessage',\n\t\t} as any);\n\t}\n\n\tconst room = await Rooms.findOneById(roomId);\n\tif (!room) {\n\t\treturn false;\n\t}\n\n\tif (user?.type !== 'app' && !(await canAccessRoomAsync(room, user))) {\n\t\treturn false;\n\t}\n\n\tcheck(\n\t\tmsgData,\n\t\tMatch.Maybe({\n\t\t\tavatar: Match.Optional(String),\n\t\t\temoji: Match.Optional(String),","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/sendFileMessage.ts#L170-L206","documentation":"The exported server-side sendFileMessage(userId, { roomId, file, msgData }) helper loads the sender with Users.findOneById(userId) and throws error-invalid-user when the record is missing. This is the internal variant used by REST handlers, apps and integrations, so the id arrives as a parameter rather than from the DDP connection.","triggerScenarios":"Passing a userId that was deleted between request start and processing; an apps-engine or REST handler forwarding a stale uid; swapped arguments (e.g. passing roomId where userId is expected); typo'd or truncated user id.","commonSituations":"Offboarding deletes a user while a queued bot job still references them; migration scripts with dirty user data; custom integration constructing the call with the wrong variable order.","solutions":["Verify the user exists before invoking the helper server-side","Check the argument order: sendFileMessage(userId, { roomId, file, msgData })","If the sender was deleted, drop the request instead of retrying - it will never succeed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// server-side caller: verify the sender before sending\nimport { Users } from '@rocket.chat/models';\n\nconst user = await Users.findOneById(userId, { projection: { username: 1 } });\nif (!user?.username) {\n\tthrow new Error(`sender ${userId} does not exist`);\n}\nreturn sendFileMessage(userId, { roomId, file, msgData });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve and validate uid parameters at the trust boundary of REST/apps handlers","Fail the job permanently when the sender was deleted instead of retrying","Double-check argument order against sendFileMessage(userId, { roomId, file, msgData })"],"tags":["server-api","file-upload","users","validation"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}