Mintplex-Labs/anything-llm · warning
Workspace ${workspaceSlug} not found
Error message
Workspace ${workspaceSlug} not found What it means
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.
Source
Thrown at server/endpoints/api/admin/index.js:629
description: "Instance is not in Multi-User mode. Method denied",
}
*/
try {
if (!multiUserMode(response)) {
response.sendStatus(401).end();
return;
}
const { workspaceSlug } = request.params;
const { userIds: _uids, reset = false } = reqBody(request);
const userIds = (
await User.where({ id: { in: _uids.map(Number) } })
).map((user) => user.id);
const workspace = await Workspace.get({ slug: String(workspaceSlug) });
const workspaceUsers = await Workspace.workspaceUsers(workspace.id);
if (!workspace) {
response.status(404).json({
success: false,
error: `Workspace ${workspaceSlug} not found`,
users: workspaceUsers,
});
return;
}
if (userIds.length === 0) {
response.status(404).json({
success: false,
error: `No valid user IDs provided.`,
users: workspaceUsers,
});
return;
}
// Reset all users in the workspace and add the new users as the only users in the workspace
if (reset) {View on GitHub (pinned to 3aec848f28)
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
Example fix
// before
const workspace = await Workspace.get({ slug: String(workspaceSlug) });
const workspaceUsers = await Workspace.workspaceUsers(workspace.id); // throws when null
if (!workspace) { /* 404 unreachable */ }
// after
const workspace = await Workspace.get({ slug: String(workspaceSlug) });
if (!workspace) {
return response.status(404).json({ success:false, error:`Workspace ${workspaceSlug} not found`, users: [] });
}
const workspaceUsers = await Workspace.workspaceUsers(workspace.id); Defensive patterns
Strategy: validation
Validate before calling
async function workspaceSlugExists(slug) {
const res = await fetch('/api/v1/workspaces'); // admin workspaces list
if (!res.ok) throw new Error(`cannot list workspaces: ${res.status}`);
const { workspaces } = await res.json();
return workspaces.some(w => w.slug === String(slug));
} Type guard
function isWorkspaceSlug(v) {
return typeof v === 'string' && /^[a-z0-9-]+$/.test(v) && !v.includes('..');
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Slug changed by re-creating a workspace; scripts with hardcoded slugs; workspace slugs containing case or encoding differences from what was passed.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- No valid user IDs provided.
- Invite not found or already disabled
- no pending help request with that id
- File not found: ${filename}
- Not found
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/7d39a64142c6baaf.
Report an issue: GitHub.