{"record":{"id":"4c2bb5ede9d70082","repo":"davila7/claude-code-templates","slug":"failed-to-get-system-health","errorCode":null,"errorMessage":"Failed to get system health","messagePattern":"Failed to get system health","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cli-tool/src/analytics.js","lineNumber":1107,"sourceCode":"            ...stats.cache,\n            dataCache: this.dataCache.getStats()\n          },\n          errors: stats.errors,\n          counters: stats.counters,\n          timestamp: Date.now()\n        };\n\n        // Determine overall health status\n        if (stats.errors.total > 10) {\n          systemHealth.status = 'degraded';\n        }\n        if (stats.memory.current && stats.memory.current.heapUsed > this.performanceMonitor.options.memoryThreshold) {\n          systemHealth.status = 'warning';\n        }\n\n        res.json(systemHealth);\n      } catch (error) {\n        res.status(500).json({\n          status: 'error',\n          message: 'Failed to get system health',\n          timestamp: Date.now()\n        });\n      }\n    });\n\n    // Version endpoint\n    this.app.get('/api/version', (req, res) => {\n      res.json({\n        version: packageJson.version,\n        name: packageJson.name,\n        description: packageJson.description,\n        timestamp: Date.now()\n      });\n    });\n\n    // Claude session information endpoint","sourceCodeStart":1089,"sourceCodeEnd":1125,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/analytics.js#L1089-L1125","documentation":"500 from GET /api/system-health. The handler builds a health report from performanceMonitor stats; failures in collecting process memory/uptime (or the monitor not being initialized) throw and this generic 500 is returned.","triggerScenarios":"GET /api/system-health when this.performanceMonitor or its stats are undefined, or when reading process.memoryUsage()/event loop metrics fails in a constrained environment.","commonSituations":"Accessing the health endpoint before the server finished initializing, or running under a runtime where perf APIs behave differently (very old/new Node).","solutions":["Confirm the analytics server fully started before polling health","Check the Node version meets the CLI's requirement","Restart the analytics server and re-hit the endpoint","Inspect performanceMonitor initialization in analytics.js for undefined options (e.g. memoryThreshold)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"await fetch(base + '/api/system-health').then(r => { if (!r.ok) throw new Error('server not ready'); });","typeGuard":"const isHealthReport = (d) => d && typeof d.status === 'string' && typeof d.timestamp === 'number';","tryCatchPattern":"try { const h = await getHealth(); if (!isHealthReport(h)) throw new Error('malformed health payload'); } catch { showDegradedBanner(); }","preventionTips":["Wait for server startup logs before monitoring","Treat health 500 as 'unknown' rather than 'down' in dashboards"],"tags":["analytics","express","http-500","health-check"],"backgroundTag":"health-check-endpoint-failure","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}