davila7/claude-code-templates · error

Failed to get performance metrics

Error message

Failed to get performance metrics

What it means

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.

Source

Thrown at cli-tool/src/analytics.js:1153

        res.status(500).json({ 
          error: 'Failed to get Claude session info',
          timestamp: Date.now()
        });
      }
    });

    // Performance metrics endpoint
    this.app.get('/api/system/metrics', (req, res) => {
      try {
        const timeframe = parseInt(req.query.timeframe) || 300000; // 5 minutes default
        const stats = this.performanceMonitor.getStats(timeframe);
        res.json({
          ...stats,
          dataCache: this.dataCache.getStats(),
          timestamp: Date.now()
        });
      } catch (error) {
        res.status(500).json({
          error: 'Failed to get performance metrics',
          timestamp: Date.now()
        });
      }
    });

    // Cache management endpoint
    this.app.post('/api/cache/clear', (req, res) => {
      try {
        // Clear specific cache types or all
        const { type } = req.body;
        
        if (!type || type === 'all') {
          // Clear all caches
          this.dataCache.invalidateComputations();
          this.dataCache.caches.parsedConversations.clear();
          this.dataCache.caches.fileContent.clear();
          this.dataCache.caches.fileStats.clear();

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Wait for the server's startup logs before hitting /api/performance
  2. Restart the analytics server
  3. Clear caches via POST /api/clear-cache to reset dataCache state
  4. Check console for the underlying exception and report if getStats() itself fails
Defensive patterns

Strategy: retry

Validate before calling

const ready = await fetch(base + '/api/conversations').then(r => r.ok); // server initialized if data endpoints work

Type guard

const isPerfStats = (d) => d && d.dataCache && typeof d.timestamp === 'number';

Try / catch

try { return await getPerformance(); } catch { await delay(1500); return await getPerformance(); } // one retry after init race

Prevention

When it happens

Trigger: GET /api/performance when this.dataCache is not initialized (endpoint hit before initialize() completed) or when getStats() throws due to internal state corruption.

Common situations: Polling metrics immediately at server startup; a partially failed cache warm-up.

Related errors


AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28). Data as JSON: /api/errors/8e2ac5e7378e9e8d. Report an issue: GitHub.