{"record":{"id":"719cc46c8e8dfb58","repo":"Mintplex-Labs/anything-llm","slug":"internal-server-error-719cc4","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/api/workspace/index.js","lineNumber":105,"sourceCode":"        response.status(400).json({ workspace: null, message });\n        return;\n      }\n\n      await Telemetry.sendTelemetry(\"workspace_created\", {\n        multiUserMode: multiUserMode(response),\n        LLMSelection: process.env.LLM_PROVIDER || \"openai\",\n        Embedder: process.env.EMBEDDING_ENGINE || \"inherit\",\n        VectorDbSelection: process.env.VECTOR_DB || \"lancedb\",\n        TTSSelection: process.env.TTS_PROVIDER || \"native\",\n        LLMModel: getModelTag(),\n      });\n      await EventLogs.logEvent(\"api_workspace_created\", {\n        workspaceName: workspace?.name || \"Unknown Workspace\",\n      });\n      response.status(200).json({ workspace, message });\n    } catch (e) {\n      console.error(e.message, e);\n      response.sendStatus(500).end();\n    }\n  });\n\n  app.get(\"/v1/workspaces\", [validApiKey], async (request, response) => {\n    /*\n    #swagger.tags = ['Workspaces']\n    #swagger.description = 'List all current workspaces'\n    #swagger.responses[200] = {\n      content: {\n        \"application/json\": {\n          schema: {\n            type: 'object',\n            example: {\n              workspaces: [\n                {\n                  \"id\": 79,\n                  \"name\": \"Sample workspace\",\n                  \"slug\": \"sample-workspace\",","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/api/workspace/index.js#L87-L123","documentation":"POST /v1/workspace/new calls `Workspace.new(name, null, additionalFields)`; expected validation failures (missing/invalid name) return 400 with a message, so the sendStatus 500 from this catch means Workspace.new threw — typically a Prisma write error such as a unique-slug collision race or DB unavailability, or an unexpected type in additionalFields. Post-creation telemetry is internally try/caught, but the EventLogs insert and any Prisma throw also land here. The real error is on the server console.","triggerScenarios":"Two concurrent creations resolving to the same slugified name (unique constraint P2002); database unreachable at insert time; passing additionalFields containing keys with wrong types (e.g. openAiHistory: 'many') that violate the column type.","commonSituations":"Automation scripts creating many similarly-named workspaces ('Test', 'Test 2') racing slug generation; DB restarts during bulk provisioning; clients forwarding arbitrary JSON into the body which is spread into Workspace.new.","solutions":["Check server logs for the Prisma error code (P2002 = duplicate slug, P1001 = connection)","If duplicate slug: fetch GET /v1/workspaces and either reuse the existing workspace or send a more unique name","Send only known workspace fields (name, openAiTemp, openAiHistory, openAiPrompt, similarityThreshold, chatProvider, chatModel) with correct types","Retry after confirming DB health with GET /v1/system"],"exampleFix":"// before\nconst res = await fetch(`${base}/api/v1/workspace/new`, {method:'POST', headers, body: JSON.stringify({name:'Test'})});\n\n// after\nconst name = `Test-${Date.now()}`; // avoid slug collisions on concurrent creates\nconst res = await fetch(`${base}/api/v1/workspace/new`, {method:'POST', headers, body: JSON.stringify({name})});\nif (res.status === 400) throw new Error((await res.json()).message); // validation\nif (res.status === 500) throw new Error('workspace create threw - check server log');","handlingStrategy":"validation","validationCode":"const nameOk = typeof name === 'string' && name.trim().length > 0 && name.length <= 100;\nif (!nameOk) throw new Error('workspace name required');","typeGuard":"const isWorkspaceCreateBody = (b) => b != null && typeof b.name === 'string' && b.name.trim().length > 0;","tryCatchPattern":"try { const r = await post(newWorkspaceUrl, {name}); if (r.status===400) throw new Error((await r.json()).message); if (r.status===500) throw new Error('create threw (duplicate slug / DB) - retry with unique name'); } catch (e) { throw e; }","preventionTips":["Generate unique names (suffix timestamp/uuid) when creating in bulk","Send only known workspace fields with native types","Store returned slug immediately - it is the key for all later calls"],"tags":["anythingllm","workspace","prisma","unique-constraint","http-500"],"backgroundTag":"workspace-creation-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}