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
- File/inspect an upstream issue with the sysctl name and Go type printed in the message
- Pin/verify the prometheus/procfs version used at build time
- 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
- Avoid local forks that change value types in newMetrics
- Keep node_exporter and prometheus/procfs at pinned, tested versions
- Treat this as a bug report trigger, not a config issue
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
- unable to retrieve limit number of threads
- unable to retrieve limit number of maximum pids allowed
- failed to open sysfs
- error obtaining sysctl info
- sysctl has no values
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)