prometheus/node_exporter · error

unexpected type %T

Error message

unexpected type %T

What it means

newMappedMetrics received a value type that is neither []int nor []string. Given newMetrics only produces those two types, reaching this default branch signals an internal invariant violation in the collector.

Solutions

  1. File/inspect an upstream issue with the sysctl name and Go type printed in the message
  2. Pin/verify the prometheus/procfs version used at build time
  3. Add handling for the new type in newMappedMetrics if patching locally
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil && strings.Contains(err.Error(), "unexpected type") {
    logger.Error("sysctl collector invariant violated", "err", err) // report upstream
}

Prevention

When it happens

Trigger: Should be unreachable in normal operation; would require newMetrics returning a value slice of an unexpected type into newMappedMetrics.

Common situations: Only after local modifications to the collector or a procfs library change returning a novel slice type.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of prometheus/node_exporter@17ddd77c59 (2026-09-07). Data as JSON: /api/errors/d6d7145ea136e181. Report an issue: GitHub.

Appendix: source

Thrown at collector/sysctl_linux.go:216

func (s *sysctl) newMappedMetrics(v any) ([]prometheus.Metric, error) {
	switch values := v.(type) {
	case []int:
		metrics := make([]prometheus.Metric, len(values))
		for i, n := range values {
			key := s.keys[i]
			desc := prometheus.NewDesc(
				prometheus.BuildFQName(namespace, "sysctl", s.metricName()+"_"+key),
				fmt.Sprintf("sysctl %s, field %d", s.name, i),
				nil,
				nil,
			)
			metrics[i] = prometheus.MustNewConstMetric(desc, prometheus.UntypedValue, float64(n))
		}
		return metrics, nil
	case []string:
		return nil, fmt.Errorf("mapped sysctl string values not supported")
	default:
		return nil, fmt.Errorf("unexpected type %T", values)
	}
}

View on GitHub (pinned to 17ddd77c59)