davila7/claude-code-templates · error

Failed to get system health

Error message

Failed to get system health

What it means

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.

Source

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

            ...stats.cache,
            dataCache: this.dataCache.getStats()
          },
          errors: stats.errors,
          counters: stats.counters,
          timestamp: Date.now()
        };

        // Determine overall health status
        if (stats.errors.total > 10) {
          systemHealth.status = 'degraded';
        }
        if (stats.memory.current && stats.memory.current.heapUsed > this.performanceMonitor.options.memoryThreshold) {
          systemHealth.status = 'warning';
        }

        res.json(systemHealth);
      } catch (error) {
        res.status(500).json({
          status: 'error',
          message: 'Failed to get system health',
          timestamp: Date.now()
        });
      }
    });

    // Version endpoint
    this.app.get('/api/version', (req, res) => {
      res.json({
        version: packageJson.version,
        name: packageJson.name,
        description: packageJson.description,
        timestamp: Date.now()
      });
    });

    // Claude session information endpoint

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Confirm the analytics server fully started before polling health
  2. Check the Node version meets the CLI's requirement
  3. Restart the analytics server and re-hit the endpoint
  4. Inspect performanceMonitor initialization in analytics.js for undefined options (e.g. memoryThreshold)
Defensive patterns

Strategy: fallback

Validate before calling

await fetch(base + '/api/system-health').then(r => { if (!r.ok) throw new Error('server not ready'); });

Type guard

const isHealthReport = (d) => d && typeof d.status === 'string' && typeof d.timestamp === 'number';

Try / catch

try { const h = await getHealth(); if (!isHealthReport(h)) throw new Error('malformed health payload'); } catch { showDegradedBanner(); }

Prevention

When it happens

Trigger: 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.

Common situations: Accessing the health endpoint before the server finished initializing, or running under a runtime where perf APIs behave differently (very old/new Node).

Related errors


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