{"record":{"id":"8ddf29f09c88a17b","repo":"RocketChat/Rocket.Chat","slug":"invalid-user-8ddf29","errorCode":"invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/rooms/settings/saveRoomEncrypted.ts","lineNumber":19,"sourceCode":"import { Message } from '@rocket.chat/core-services';\nimport type { IUser } from '@rocket.chat/core-typings';\nimport { isRegisterUser } from '@rocket.chat/core-typings';\nimport { Rooms, Subscriptions } from '@rocket.chat/models';\nimport { Match } from 'meteor/check';\nimport { Meteor } from 'meteor/meteor';\nimport type { UpdateResult } from 'mongodb';\n\nimport { notifyOnSubscriptionChangedByRoomId } from '../../notifyListener';\n\nexport const saveRoomEncrypted = async function (rid: string, encrypted: boolean, user: IUser, sendMessage = true): Promise<UpdateResult> {\n\tif (!Match.test(rid, String)) {\n\t\tthrow new Meteor.Error('invalid-room', 'Invalid room', {\n\t\t\tfunction: 'RocketChat.saveRoomEncrypted',\n\t\t});\n\t}\n\n\tif (!isRegisterUser(user)) {\n\t\tthrow new Meteor.Error('invalid-user', 'Invalid user', {\n\t\t\tfunction: 'RocketChat.saveRoomEncrypted',\n\t\t});\n\t}\n\n\tconst update = await Rooms.saveEncryptedById(rid, encrypted);\n\tif (update && sendMessage) {\n\t\tconst type = encrypted ? 'room_e2e_enabled' : 'room_e2e_disabled';\n\n\t\tawait Message.saveSystemMessage(type, rid, user.username, user);\n\t}\n\n\tif (encrypted) {\n\t\tconst { modifiedCount } = await Subscriptions.disableAutoTranslateByRoomId(rid);\n\t\tif (modifiedCount) {\n\t\t\tvoid notifyOnSubscriptionChangedByRoomId(rid);\n\t\t}\n\t}\n\treturn update;","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/rooms/settings/saveRoomEncrypted.ts#L1-L37","documentation":"Thrown by saveRoomEncrypted when isRegisterUser(user) is false (saveRoomEncrypted.ts:19). isRegisterUser (packages/core-typings/src/IUser.ts:255) requires user.username !== undefined && user.name !== undefined, so partial user objects and nameless app/bot users fail. Code 'invalid-user', details { function: 'RocketChat.saveRoomEncrypted' }.","triggerScenarios":"Passing a user stub like { _id } from a method context without fetching the document; bots/apps users lacking name; test fixtures with only _id/username; passing the acting app user instead of the human owner.","commonSituations":"Server code using Meteor.user() partial projections that omitted name; scripts driving the e2e toggle with hardcoded minimal users.","solutions":["Load the full user: const user = await Users.findOneById(userId) and pass that","Ensure the user profile has a non-empty name and a username","Pre-check with isRegisterUser(user) from '@rocket.chat/core-typings'","Match on code 'invalid-user' (no error- prefix) when catching"],"exampleFix":"// before\nawait saveRoomEncrypted(rid, encrypted, { _id: uid } as IUser);\n\n// after\nconst user = await Users.findOneById(uid);\nif (!user || !isRegisterUser(user)) {\n\tthrow new Meteor.Error('invalid-user', 'Invalid user', { function: 'RocketChat.saveRoomEncrypted' });\n}\nawait saveRoomEncrypted(rid, encrypted, user);","handlingStrategy":"type-guard","validationCode":"const user = await Users.findOneById(userId);\nif (!user || !isRegisterUser(user)) {\n\tthrow new Meteor.Error('invalid-user', 'Invalid user', { function: 'RocketChat.saveRoomEncrypted' });\n}\nawait saveRoomEncrypted(rid, encrypted, user);","typeGuard":"import { isRegisterUser } from '@rocket.chat/core-typings';\n// narrows IUser to IRegisterUser when username AND name are defined\nconst canOperate = (u: IUser): boolean => isRegisterUser(u);","tryCatchPattern":null,"preventionTips":["Fetch the full user document rather than trusting partial session projections","Ensure profiles have name set (bots/apps often lack it)","Catch on exact code 'invalid-user'"],"tags":["e2e-encryption","user","validation","type-guard"],"backgroundTag":"incomplete-user-object","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}