{"record":{"id":"b410e262cea19044","repo":"Mintplex-Labs/anything-llm","slug":"internal-server-error-b410e2","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/utils.js","lineNumber":31,"sourceCode":"function utilEndpoints(app) {\n  if (!app) return;\n\n  app.get(\"/utils/metrics\", async (_, response) => {\n    try {\n      const metrics = {\n        online: true,\n        version: getGitVersion(),\n        mode: (await SystemSettings.isMultiUserMode())\n          ? \"multi-user\"\n          : \"single-user\",\n        vectorDB: process.env.VECTOR_DB || \"lancedb\",\n        storage: await getDiskStorage(),\n        appVersion: getDeploymentVersion(),\n      };\n      response.status(200).json(metrics);\n    } catch (e) {\n      console.error(e);\n      response.sendStatus(500).end();\n    }\n  });\n\n  app.post(\n    \"/export-chat/:type\",\n    [validatedRequest, flexUserRoleValid([ROLES.all])],\n    async (request, response) => {\n      try {\n        const { type } = request.params;\n        if (!validExportTypes.includes(type))\n          return response.sendStatus(400).end();\n\n        const { workspaceSlug, threadSlug } = reqBody(request);\n        const { Workspace } = require(\"../models/workspace\");\n        const { WorkspaceThread } = require(\"../models/workspaceThread\");\n        const { WorkspaceChats } = require(\"../models/workspaceChats\");\n\n        const user = await userFromSession(request, response);","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/utils.js#L13-L49","documentation":"Returned by GET /utils/metrics when building the system metrics object throws. The handler aggregates: `getGitVersion()` (spawns a child process — already has its own try-catch fallback returning '--'), `SystemSettings.isMultiUserMode()` (database query), `getDiskStorage()` (uses check-disk-space npm package — already has its own try-catch returning nulls), and `getDeploymentVersion()`. The outer catch at lines 29-31 sends a bare 500. Since getGitVersion and getDiskStorage have internal fallbacks, the most likely remaining throw source is `SystemSettings.isMultiUserMode()` or `getDeploymentVersion()`.","triggerScenarios":"`SystemSettings.isMultiUserMode()` throws because the system_settings table is missing or the database is inaccessible. `getDeploymentVersion()` throws if it reads a package.json or version file that is missing or malformed. On Docker deployments, `getGitVersion()` returns '--' safely, but the disk space check or system settings query can fail if the storage mount is broken.","commonSituations":"Database not initialized (fresh container with missing migration step). Storage volume not mounted correctly in Docker. A corrupted or missing package.json or version file that getDeploymentVersion reads. Running in an environment where the check-disk-space package's native dependency fails.","solutions":["Check server console for the specific error — it will reveal whether the failure is in the DB query, version lookup, or disk space check.","Verify the database is initialized and the system_settings table exists.","Check Docker volume mounts — the storage directory must be accessible.","Ensure package.json exists in the deployment root for getDeploymentVersion()."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch('/utils/metrics');\n  if (res.status === 500) {\n    // Database or system-level failure — this endpoint is a health check\n    // so failure here indicates a fundamental system issue\n    console.error('System metrics unavailable — database or storage issue');\n    return { online: false };\n  }\n  const metrics = await res.json();\n} catch (e) {\n  console.error('Metrics endpoint failed:', e.message);\n}","preventionTips":["Treat a 500 on /utils/metrics as a critical system health issue — it means the database or storage layer is broken.","Ensure the database is initialized before starting the server (run migrations).","Verify Docker volume mounts for the storage directory.","Check that package.json exists in the deployment for getDeploymentVersion()."],"tags":["metrics","system-settings","database","disk-space","health-check","internal-error"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}