{"record":{"id":"5bf8135809165cb4","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-5bf813","errorCode":"error-invalid-user","errorMessage":"The optional \"userId\" param provided does not match any users","messagePattern":"The optional \"userId\" param provided does not match any users","errorType":"exception","errorClass":"Meteor.Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/users.ts","lineNumber":247,"sourceCode":"\t\t\tauthRequired: true,\n\t\t\tbody: isUsersSetPreferencesParamsPOST,\n\t\t\tresponse: {\n\t\t\t\t200: userObjectResponse,\n\t\t\t\t400: validateBadRequestErrorResponse,\n\t\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t},\n\t\t},\n\t\tasync function action() {\n\t\t\tif (\n\t\t\t\tthis.bodyParams.userId &&\n\t\t\t\tthis.bodyParams.userId !== this.userId &&\n\t\t\t\t!(await hasPermissionAsync(this.user, 'edit-other-user-info'))\n\t\t\t) {\n\t\t\t\tthrow new Meteor.Error('error-action-not-allowed', 'Editing user is not allowed');\n\t\t\t}\n\t\t\tconst userId = this.bodyParams.userId ? this.bodyParams.userId : this.userId;\n\t\t\tif (!(await Users.findOneById(userId))) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-user', 'The optional \"userId\" param provided does not match any users');\n\t\t\t}\n\n\t\t\tawait saveUserPreferences(this.bodyParams.data, userId);\n\t\t\tconst user = await Users.findOneById(userId, {\n\t\t\t\tprojection: {\n\t\t\t\t\t'settings.preferences': 1,\n\t\t\t\t\t'language': 1,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (!user) {\n\t\t\t\treturn API.v1.failure('User not found');\n\t\t\t}\n\n\t\t\treturn API.v1.success({\n\t\t\t\tuser: {\n\t\t\t\t\t_id: user._id,\n\t\t\t\t\tsettings: {","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/users.ts#L229-L265","documentation":"Thrown by users.setPreferences after the edit-other-user check passes: Users.findOneById(userId) returns nothing, so the resolved target user does not exist.","triggerScenarios":"POST users.setPreferences with a userId (own or via edit-other-user-info) that does not match any user document.","commonSituations":"Stale userId in client state after account deletion; typo in userId; referencing a user from another workspace.","solutions":["Send a valid userId that exists in this workspace, or omit it to target yourself.","Refresh the client's cached userId from /api/v1/me before calling.","Verify the user exists via users.info before editing preferences."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Confirm target exists before editing preferences\nif (targetUserId) {\n  const u = await GET(`users.info?userId=${encodeURIComponent(targetUserId)}`);\n  if (!u?.user) return;\n}","typeGuard":"null","tryCatchPattern":"try {\n  await POST('users.setPreferences', body);\n} catch (e) {\n  if (isMeteorError(e, 'error-invalid-user')) {\n    // refresh client user list; the cached userId is stale\n  } else { throw e; }\n}","preventionTips":["Resolve the current userId from /api/v1/me rather than caching indefinitely.","Validate userIds against users.info in admin UIs before edits."],"tags":["users","validation","api"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}