{"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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/api/workspace/index.js#L87-L123","documentation":"Returned by POST /v1/workspace/new when an exception occurs after the Workspace.new call succeeds but before the response is sent, or when Workspace.new itself throws. The handler at server/endpoints/api/system index catches errors from Workspace.new (Prisma create), Telemetry.sendTelemetry (network call to telemetry endpoint), and EventLogs.logEvent (Prisma create). A subtle issue: if Workspace.new succeeds but Telemetry.sendTelemetry throws, the workspace IS created but the client sees a 500 — a silent partial-success state.","triggerScenarios":"POST /v1/workspace/new with a name that violates a DB constraint (e.g., null name when the DB column is NOT NULL without a default). Also when Telemetry.sendTelemetry throws due to network restrictions (firewall blocking the telemetry endpoint) or when EventLogs.logEvent fails (DB issue). If the Prisma `workspaces` table has a unique constraint on slug and the auto-generated slug collides, Workspace.new throws.","commonSituations":"Air-gapped or firewall-restricted deployments where the telemetry endpoint is unreachable, causing sendTelemetry to throw even though workspace creation succeeded. Database connection issues. Sending unexpected field types in additionalFields that Prisma rejects (e.g., a string where a number is expected for openAiTemp).","solutions":["Check server logs to identify whether Workspace.new, Telemetry.sendTelemetry, or EventLogs.logEvent threw — the stack trace will show which.","If telemetry is the culprit, set DISABLE_TELEMETRY or the relevant env var to disable telemetry calls (check Telemetry model for the flag).","Verify the request body: ensure `name` is a non-empty string and any additionalFields match expected types (openAiTemp as number, etc.).","After a 500, check if the workspace was actually created via GET /v1/workspaces — it may exist as a partial-success artifact.","Ensure the database is reachable and the workspaces table schema matches the Prisma schema."],"exampleFix":"// before — telemetry endpoint unreachable causes 500 even on success\n// (no env var set)\n\n// after — disable telemetry if your environment blocks outbound calls\n// In .env:\n// DISABLE_TELEMETRY_EVENTS=true","handlingStrategy":"try-catch","validationCode":"// Validate workspace creation body before sending\nfunction validateNewWorkspaceBody(body) {\n  if (!body.name || typeof body.name !== 'string')\n    return { valid: false, error: 'name is required and must be a string' };\n  if (body.openAiTemp != null && typeof body.openAiTemp !== 'number')\n    return { valid: false, error: 'openAiTemp must be a number' };\n  if (body.openAiHistory != null && typeof body.openAiHistory !== 'number')\n    return { valid: false, error: 'openAiHistory must be a number' };\n  return { valid: true };\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch('/v1/workspace/new', {\n    method: 'POST',\n    headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${API_KEY}` },\n    body: JSON.stringify({ name: 'My Workspace' })\n  });\n  if (res.status === 500) {\n    // CRITICAL: workspace may have been created before telemetry threw.\n    // Verify via list endpoint\n    const { workspaces } = await (await fetch('/v1/workspaces', {\n      headers: { Authorization: `Bearer ${API_KEY}` }\n    })).json();\n    const created = workspaces.find(w => w.name === 'My Workspace');\n    if (created) return created; // partial success — workspace exists\n    throw new Error('Workspace creation failed entirely');\n  }\n  return await res.json();\n} catch (e) { console.error(e); }","preventionTips":["After a 500 on workspace creation, always verify via GET /v1/workspaces whether the workspace was partially created.","Disable telemetry in air-gapped/firewalled environments to prevent telemetry-throws from masking successful operations.","Send only the `name` field for basic workspace creation — omit optional fields unless needed.","Ensure all optional fields have the correct JS type (numbers for numeric fields)."],"tags":["workspace","express","anythingllm","telemetry","partial-success"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}