{"record":{"id":"24f3219a9d096a95","repo":"Mintplex-Labs/anything-llm","slug":"no-valid-user-ids-provided","errorCode":null,"errorMessage":"No valid user IDs provided.","messagePattern":"No valid user IDs provided\\.","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"server/endpoints/api/admin/index.js","lineNumber":638,"sourceCode":"        const { workspaceSlug } = request.params;\n        const { userIds: _uids, reset = false } = reqBody(request);\n        const userIds = (\n          await User.where({ id: { in: _uids.map(Number) } })\n        ).map((user) => user.id);\n        const workspace = await Workspace.get({ slug: String(workspaceSlug) });\n        const workspaceUsers = await Workspace.workspaceUsers(workspace.id);\n\n        if (!workspace) {\n          response.status(404).json({\n            success: false,\n            error: `Workspace ${workspaceSlug} not found`,\n            users: workspaceUsers,\n          });\n          return;\n        }\n\n        if (userIds.length === 0) {\n          response.status(404).json({\n            success: false,\n            error: `No valid user IDs provided.`,\n            users: workspaceUsers,\n          });\n          return;\n        }\n\n        // Reset all users in the workspace and add the new users as the only users in the workspace\n        if (reset) {\n          const { success, error } = await Workspace.updateUsers(\n            workspace.id,\n            userIds\n          );\n          return response.status(200).json({\n            success,\n            error,\n            users: await Workspace.workspaceUsers(workspace.id),\n          });","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/api/admin/index.js#L620-L656","documentation":"Returned by the workspace-users update endpoint when, after filtering `reqBody.userIds.map(Number)` against User.where({id:{in:...}}), zero users match. So every provided id was nonexistent or non-numeric (NaN matches nothing). Note two adjacent hazards: userIds omitted entirely makes `.map` throw (500), and this validation uses 404 for what is really a 400-class input problem.","triggerScenarios":"POST with userIds:[999999] (deleted users), userIds:['abc'] (non-numeric strings -> NaN), or ids valid in another environment but not this one. userIds undefined or not an array -> TypeError -> 500 instead.","commonSituations":"Hardcoded user id lists drifting after DB resets; passing usernames or usernames-as-strings instead of numeric ids; environment mismatch between staging and production user tables.","solutions":["Fetch the user list from the admin API first and send only existing integer ids: userIds:[1,2,3]","Ensure the field is an array of numbers (or numeric strings) — never omit it, never send usernames","Validate client-side that every entry passes Number.isInteger(Number(x))"],"exampleFix":"// before\n{ userIds: ['sam', '2'] } // 'sam' -> NaN, so only id 2 matches; if none match -> 404\n\n// after\nconst users = await getUsers();\nconst ids = ['sam','2'].map(Number).filter(Number.isInteger)\n  .filter(id => users.some(u => u.id === id));\nif (ids.length === 0) throw new Error('no valid users');\n{ userIds: ids }","handlingStrategy":"validation","validationCode":"function normalizeUserIds(ids, knownUsers) {\n  if (!Array.isArray(ids)) throw new TypeError('userIds must be an array');\n  const valid = ids.map(Number).filter(n => Number.isInteger(n));\n  const existing = valid.filter(n => knownUsers.some(u => u.id === n));\n  if (existing.length === 0) throw new Error('no valid user ids — nothing to do');\n  return existing;\n}","typeGuard":"function isUserIdsPayload(b) {\n  return Boolean(b) && Array.isArray(b.userIds) &&\n    b.userIds.length > 0 &&\n    b.userIds.every(x => Number.isInteger(Number(x)) && String(x).trim() !== '');\n}","tryCatchPattern":null,"preventionTips":["Always send userIds as a non-empty array of integers matching existing users","Fetch the admin users list first and map usernames to ids client-side","Never omit userIds — the server .map()s it unguarded and a missing field becomes a 500"],"tags":["admin-api","workspaces","user-ids","http-404","input-validation"],"backgroundTag":"request-body-validation","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}