{"record":{"id":"cb4268aba49806a4","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-cb4268","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/slashcommands/archiveroom/server.ts","lineNumber":38,"sourceCode":"\t\tlet room;\n\n\t\tif (channel === '') {\n\t\t\troom = await Rooms.findOneById(message.rid);\n\t\t\tif (room?.name) {\n\t\t\t\tchannel = room.name;\n\t\t\t}\n\t\t} else {\n\t\t\tchannel = channel.replace('#', '');\n\t\t\troom = await Rooms.findOneByName(channel);\n\t\t}\n\n\t\tif (!userId) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\n\t\tif (!user || !isRegisterUser(user)) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n\t\t}\n\n\t\tif (!room) {\n\t\t\tvoid api.broadcast('notify.ephemeralMessage', userId, message.rid, {\n\t\t\t\tmsg: i18n.t('Channel_doesnt_exist', {\n\t\t\t\t\tchannelName: channel,\n\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\tif (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE, userId))) {\n\t\t\tthrow new Meteor.Error('error-room-type-not-archivable', `Room type: ${room.t} can not be archived`);\n\t\t}\n\n\t\tif (!(await hasPermissionAsync(userId, 'archive-room', room._id))) {\n\t\t\tthrow new Meteor.Error('error-not-authorized', 'Not authorized');","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/slashcommands/archiveroom/server.ts#L20-L56","documentation":"The /archive slash command resolves the executing user with Users.findOneById(userId, { username, name }) and requires isRegisterUser - which per core-typings means the user document must have both username and name defined. A missing user record (userId no longer in the users collection) or an incomplete user doc (no name or no username) fails with 'error-invalid-user' before any room logic runs.","triggerScenarios":"Running /archive from a session whose user was deleted between connection and command processing; users created by imports or bots without a name field; token or session reuse after the account was removed.","commonSituations":"Deleted-but-still-connected sessions; bulk-imported users missing profile names; broken user-creation extensions that omit required fields.","solutions":["Verify the user record exists and has both username and name before dispatching commands","Backfill missing name or username fields on imported users","Terminate sessions of deleted users so stale commands cannot fire","Re-run the command from a healthy account after fixing the user document"],"exampleFix":"// before\nconst user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\nif (!user || !isRegisterUser(user)) throw new Meteor.Error('error-invalid-user', 'Invalid user');\n\n// after - guard at the caller so the command gets a complete user\nif (!user || user.username === undefined || user.name === undefined) {\n\treturn notifyUser('Your profile is incomplete (name/username missing); fix it before using /archive');\n}","handlingStrategy":"validation","validationCode":"const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\nif (!user || user.username === undefined || user.name === undefined) {\n\treturn refuse('Your user record is incomplete (missing name or username)');\n}\nrunCommand('/archive', room);","typeGuard":"const isRegisterUser = (u: { username?: string; name?: string } | null | undefined): u is { username: string; name: string } =>\n\tBoolean(u && u.username !== undefined && u.name !== undefined);","tryCatchPattern":"catch (err) {\n\tif (err instanceof Meteor.Error && err.error === 'error-invalid-user') {\n\t\t// session references a missing or incomplete user: log out and re-authenticate\n\t} else throw err;\n}","preventionTips":["Backfill name and username on imported users before enabling slash commands","Kill sessions of deleted users promptly","Require complete profiles (name) for accounts allowed to run moderation commands"],"tags":["slash-command","user-validation","archive","user-record"],"backgroundTag":"invalid-user-record","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}