{"record":{"id":"7d39a64142c6baaf","repo":"Mintplex-Labs/anything-llm","slug":"workspace-workspaceslug-not-found","errorCode":null,"errorMessage":"Workspace ${workspaceSlug} not found","messagePattern":"Workspace (.+?) not found","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"server/endpoints/api/admin/index.js","lineNumber":629,"sourceCode":"      description: \"Instance is not in Multi-User mode. Method denied\",\n    }\n    */\n      try {\n        if (!multiUserMode(response)) {\n          response.sendStatus(401).end();\n          return;\n        }\n\n        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) {","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/api/admin/index.js#L611-L647","documentation":"Intended 404 of PUT/POST /v1/admin/workspace-users/:workspaceSlug when Workspace.get({slug}) finds nothing. Critical caveat: the code calls `await Workspace.workspaceUsers(workspace.id)` BEFORE the null check (admin/index.js:626), so a missing workspace actually throws 'Cannot read properties of null' there, which the outer catch converts to a bare 500. The 'Workspace not found' 404 is effectively unreachable as written.","triggerScenarios":"POST /v1/admin/workspace-users/<wrong-slug> — slug typo, workspace deleted, or slug from another environment. As coded you receive 500 (null deref) rather than this 404; you only see the 404 in builds where the lines are reordered.","commonSituations":"Slug changed by re-creating a workspace; scripts with hardcoded slugs; workspace slugs containing case or encoding differences from what was passed.","solutions":["Verify the slug first via the workspaces admin API (GET /v1/workspaces or admin list) and use the exact slug string","If you maintain the server, move the `if (!workspace)` check above the workspaceUsers call so callers get the intended 404 instead of 500","Check server console: 'TypeError: Cannot read properties of null (reading id)' confirms the ordering bug"],"exampleFix":"// before\nconst workspace = await Workspace.get({ slug: String(workspaceSlug) });\nconst workspaceUsers = await Workspace.workspaceUsers(workspace.id); // throws when null\nif (!workspace) { /* 404 unreachable */ }\n\n// after\nconst workspace = await Workspace.get({ slug: String(workspaceSlug) });\nif (!workspace) {\n  return response.status(404).json({ success:false, error:`Workspace ${workspaceSlug} not found`, users: [] });\n}\nconst workspaceUsers = await Workspace.workspaceUsers(workspace.id);","handlingStrategy":"validation","validationCode":"async function workspaceSlugExists(slug) {\n  const res = await fetch('/api/v1/workspaces'); // admin workspaces list\n  if (!res.ok) throw new Error(`cannot list workspaces: ${res.status}`);\n  const { workspaces } = await res.json();\n  return workspaces.some(w => w.slug === String(slug));\n}","typeGuard":"function isWorkspaceSlug(v) {\n  return typeof v === 'string' && /^[a-z0-9-]+$/.test(v) && !v.includes('..');\n}","tryCatchPattern":null,"preventionTips":["Verify the slug via the workspaces API before calling workspace-users updates","Expect a 500 (not 404) for a bad slug on current builds — the null check sits after workspaceUsers()","If you run the server, reorder the null check above the workspaceUsers call to fix the latent bug"],"tags":["admin-api","workspaces","http-404","null-deref","ordering-bug"],"backgroundTag":"resource-not-found","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"}