{"record":{"id":"9b5ff515ce8bdd5a","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-desired-user","errorCode":"error-invalid-desired-user","errorMessage":"Invalid desired user","messagePattern":"Invalid desired user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/users/setUserAvatar.ts","lineNumber":58,"sourceCode":"\t\t});\n\t}\n\n\tlet user: IUser | null;\n\n\tif (targetUserId && targetUserId !== userId) {\n\t\tif (!(await hasPermissionAsync(userId, 'edit-other-user-avatar'))) {\n\t\t\tthrow new Meteor.Error('error-unauthorized', 'Unauthorized', {\n\t\t\t\tmethod: 'setAvatarFromService',\n\t\t\t});\n\t\t}\n\n\t\tuser = await Users.findOneById(targetUserId, { projection: { _id: 1, username: 1 } });\n\t} else {\n\t\tuser = await Users.findOneById(userId, { projection: { _id: 1, username: 1 } });\n\t}\n\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-desired-user', 'Invalid desired user', {\n\t\t\tmethod: 'setAvatarFromService',\n\t\t});\n\t}\n\n\treturn setUserAvatar(user, dataURI, contentType, service);\n};\n\nexport function setUserAvatar(\n\tuser: Pick<IUser, '_id' | 'username'>,\n\tdataURI: Buffer,\n\tcontentType: string,\n\tservice: 'rest',\n\tetag?: string,\n\tupdater?: Updater<IUser>,\n\tsession?: ClientSession,\n): Promise<void>;\nexport function setUserAvatar(\n\tuser: Pick<IUser, '_id' | 'username'>,","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/users/setUserAvatar.ts#L40-L76","documentation":"After the setting and permission checks, setAvatarFromServiceWithValidation fetches the target user document (targetUserId when editing someone else, otherwise the actor). If no document matches, error-invalid-desired-user is thrown. Distinct from error-invalid-user (falsy acting id): here the lookup of the intended avatar owner failed.","triggerScenarios":"setAvatarFromService with a targetUserId that was deleted or never existed; admin UI holding a stale user id from a listing made before deletion; ids from another environment.","commonSituations":"User deleted between directory listing and the avatar action; wrong environment's user id; typo'd or truncated target id in integrations.","solutions":["Verify the target user exists first (users.info API or Users.findOneById).","Refresh stale ids from the current user directory before retrying.","Handle deletion races by re-checking the target right before the operation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const target = await Users.findOneById(targetUserId ?? userId, { projection: { _id: 1 } });\nif (!target) {\n  throw new Meteor.Error('error-invalid-desired-user', 'Invalid desired user', { targetUserId });\n}\nawait setAvatarFromServiceWithValidation(userId, dataURI, contentType, service, targetUserId);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate target user ids (users.info) before avatar operations from admin tooling.","Re-check existence after long-lived admin sessions that list users."],"tags":["avatar","user-management","validation"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}