{"record":{"id":"8e2ac5e7378e9e8d","repo":"davila7/claude-code-templates","slug":"failed-to-get-performance-metrics","errorCode":null,"errorMessage":"Failed to get performance metrics","messagePattern":"Failed to get performance metrics","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cli-tool/src/analytics.js","lineNumber":1153,"sourceCode":"        res.status(500).json({ \n          error: 'Failed to get Claude session info',\n          timestamp: Date.now()\n        });\n      }\n    });\n\n    // Performance metrics endpoint\n    this.app.get('/api/system/metrics', (req, res) => {\n      try {\n        const timeframe = parseInt(req.query.timeframe) || 300000; // 5 minutes default\n        const stats = this.performanceMonitor.getStats(timeframe);\n        res.json({\n          ...stats,\n          dataCache: this.dataCache.getStats(),\n          timestamp: Date.now()\n        });\n      } catch (error) {\n        res.status(500).json({\n          error: 'Failed to get performance metrics',\n          timestamp: Date.now()\n        });\n      }\n    });\n\n    // Cache management endpoint\n    this.app.post('/api/cache/clear', (req, res) => {\n      try {\n        // Clear specific cache types or all\n        const { type } = req.body;\n        \n        if (!type || type === 'all') {\n          // Clear all caches\n          this.dataCache.invalidateComputations();\n          this.dataCache.caches.parsedConversations.clear();\n          this.dataCache.caches.fileContent.clear();\n          this.dataCache.caches.fileStats.clear();","sourceCodeStart":1135,"sourceCodeEnd":1171,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/analytics.js#L1135-L1171","documentation":"500 from the performance metrics endpoint. The handler merges performanceMonitor stats with dataCache stats; if either object shape is unexpected (undefined cache, missing method), the property access throws and this 500 is returned.","triggerScenarios":"GET /api/performance when this.dataCache is not initialized (endpoint hit before initialize() completed) or when getStats() throws due to internal state corruption.","commonSituations":"Polling metrics immediately at server startup; a partially failed cache warm-up.","solutions":["Wait for the server's startup logs before hitting /api/performance","Restart the analytics server","Clear caches via POST /api/clear-cache to reset dataCache state","Check console for the underlying exception and report if getStats() itself fails"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const ready = await fetch(base + '/api/conversations').then(r => r.ok); // server initialized if data endpoints work\n","typeGuard":"const isPerfStats = (d) => d && d.dataCache && typeof d.timestamp === 'number';","tryCatchPattern":"try { return await getPerformance(); } catch { await delay(1500); return await getPerformance(); } // one retry after init race","preventionTips":["Don't scrape metrics during startup","Add jitter/backoff in monitoring loops"],"tags":["analytics","express","http-500","performance-metrics"],"backgroundTag":"internal-server-error-handler","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}