{"record":{"id":"f37baa4c2f4bbd7f","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-f37baa","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/slashcommands/join/server.ts","lineNumber":47,"sourceCode":"\t\t\t\t\tlng: settings.get('Language') || 'en',\n\t\t\t\t}),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(room._id, userId, {\n\t\t\tprojection: { _id: 1 },\n\t\t});\n\n\t\tif (subscription) {\n\t\t\tthrow new Meteor.Error('error-user-already-in-room', 'You are already in the channel', {\n\t\t\t\tmethod: 'slashCommands',\n\t\t\t});\n\t\t}\n\n\t\tconst user = await Users.findOneById(userId);\n\t\tif (!user) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'slashCommands',\n\t\t\t});\n\t\t}\n\t\tawait Room.join({ room, user });\n\t},\n\toptions: {\n\t\tdescription: 'Join_the_given_channel',\n\t\tparams: '#channel',\n\t\tpermission: 'view-c-room',\n\t},\n});\n","sourceCodeStart":29,"sourceCodeEnd":59,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/slashcommands/join/server.ts#L29-L59","documentation":"Thrown by the /join slash command when Users.findOneById returns no user document for the authenticated userId. It is a defensive guard: a valid Meteor userId should always map to a Users record, so hitting it means the user was deleted, deactivated mid-request, or the users collection is inconsistent with the login token.","triggerScenarios":"/join executes after the userId's Users document was removed (user deletion raced the command), or the account exists in Meteor's login service but its Users row is missing (partial migration, restored database without users collection).","commonSituations":"Running the command from a session whose user was just deleted by an admin; database restored from backup with mismatched collections; test harnesses forging userIds that have no user document.","solutions":["Verify the Users document exists for the current userId (Users.findOneById) before invoking join flows.","If it was deleted, log the user out and re-authenticate with a valid account.","Audit for partial deletions or restores that dropped the users collection.","In custom code calling slashCommands programmatically, pass a userId known to exist."],"exampleFix":"// before\nconst user = await Users.findOneById(userId);\nif (!user) {\n  throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'slashCommands' });\n}\n\n// caller-side guard\nconst user = Meteor.user();\nif (!user) {\n  // re-authenticate instead of running /join\n}","handlingStrategy":"validation","validationCode":"const user = await Meteor.callAsync('getUser', Meteor.userId());\nif (!user) { /* session is stale: log out and re-authenticate */ }","typeGuard":"const hasValidUser = (u: unknown): u is IUser =>\n  Boolean(u) && typeof (u as IUser)._id === 'string' && Array.isArray((u as IUser).roles);","tryCatchPattern":"try { await Meteor.callAsync('slashCommand', { command: 'join', ... }); } catch (e) { if (isMeteorError(e, 'error-invalid-user')) { Meteor.logout(); /* re-login */ return; } throw e; }","preventionTips":["Authenticate with an existing, active account before running commands.","Verify Users.findOneById(Meteor.userId()) in long-lived bots at startup.","Avoid forging userIds in programmatic slash-command calls."],"tags":["rocket-chat","slash-command","user-lookup","meteor"],"backgroundTag":"entity-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}