{"record":{"id":"26004d9a70f47092","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-26004d","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/sendMessage.ts","lineNumber":76,"sourceCode":"\t\t\t\tserver_ts: new Date().getTime(),\n\t\t\t});\n\t\t}\n\t\tif (tsDiff > 10000) {\n\t\t\tmessage.ts = now;\n\t\t}\n\t}\n\n\tif (message.msg) {\n\t\tif (message.msg.length > (settings.get<number>('Message_MaxAllowedSize') ?? 0)) {\n\t\t\tthrow new Meteor.Error('error-message-size-exceeded', 'Message size exceeds Message_MaxAllowedSize', {\n\t\t\t\tmethod: 'sendMessage',\n\t\t\t});\n\t\t}\n\t}\n\n\tconst user = typeof uid === 'string' ? await Users.findOneById(uid) : uid;\n\tif (!user?.username) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user');\n\t}\n\n\tlet { rid } = message;\n\n\t// do not allow nested threads\n\tif (message.tmid) {\n\t\tconst parentMessage = await Messages.findOneById(message.tmid, { projection: { rid: 1, tmid: 1 } });\n\t\tmessage.tmid = parentMessage?.tmid || message.tmid;\n\n\t\tif (parentMessage?.rid) {\n\t\t\trid = parentMessage?.rid;\n\t\t}\n\t}\n\n\tif (!rid) {\n\t\tthrow new Error(\"The 'rid' property on the message object is missing.\");\n\t}\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/sendMessage.ts#L58-L94","documentation":"executeSendMessage resolves the sender - Users.findOneById(uid) when a string id is passed, or the provided user object - and throws error-invalid-user when the user is missing or has no username. This path is used by server-side callers (REST, apps, integrations); the Meteor method wrapper checks the connection separately.","triggerScenarios":"Server-side call with a uid of a deleted user; user record exists but username is unset (half-migrated or imported user); offboarding deletes the user while a queued job is mid-flight.","commonSituations":"Bot jobs referencing deleted accounts; LDAP/import pipelines creating users without usernames; race between deletion and in-flight sends.","solutions":["Fetch and verify the user (and that username is set) before calling executeSendMessage","Drop or re-queue the job if the sender no longer exists instead of retrying","Fix imported users that lack a username"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// server-side caller: verify the sender before executing the send\nimport { Users } from '@rocket.chat/models';\n\nconst user = typeof uid === 'string' ? await Users.findOneById(uid) : uid;\nif (!user?.username) {\n\tthrow new Error('sender missing or has no username');\n}\nawait executeSendMessage(user, message);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate uid parameters at handler entry (exists + username set)","Discard queued sends whose sender was deleted","Backfill usernames for imported users before enabling senders"],"tags":["server-api","messages","users","validation"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}