{"record":{"id":"9e786e40e3c14e76","repo":"prometheus/node_exporter","slug":"could-not-get-power-supply-class-info-w","errorCode":null,"errorMessage":"could not get power_supply class info: %w","messagePattern":"could not get power_supply class info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/powersupplyclass_linux.go","lineNumber":35,"sourceCode":"\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"regexp\"\n\t\"strings\"\n\n\t\"github.com/prometheus/client_golang/prometheus\"\n\t\"github.com/prometheus/procfs/sysfs\"\n)\n\nfunc (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error {\n\tpowerSupplyClass, err := getPowerSupplyClassInfo(c.ignoredPattern)\n\tif err != nil {\n\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\treturn ErrNoData\n\t\t}\n\t\treturn fmt.Errorf(\"could not get power_supply class info: %w\", err)\n\t}\n\tfor _, powerSupply := range powerSupplyClass {\n\n\t\tfor name, value := range map[string]*int64{\n\t\t\t\"authentic\":             powerSupply.Authentic,\n\t\t\t\"calibrate\":             powerSupply.Calibrate,\n\t\t\t\"capacity\":              powerSupply.Capacity,\n\t\t\t\"capacity_alert_max\":    powerSupply.CapacityAlertMax,\n\t\t\t\"capacity_alert_min\":    powerSupply.CapacityAlertMin,\n\t\t\t\"cyclecount\":            powerSupply.CycleCount,\n\t\t\t\"online\":                powerSupply.Online,\n\t\t\t\"present\":               powerSupply.Present,\n\t\t\t\"time_to_empty_seconds\": powerSupply.TimeToEmptyNow,\n\t\t\t\"time_to_full_seconds\":  powerSupply.TimeToFullNow,\n\t\t} {\n\t\t\tif value != nil {\n\t\t\t\tpushPowerSupplyMetric(ch, c.subsystem, name, float64(*value), powerSupply.Name, prometheus.GaugeValue)\n\t\t\t}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/powersupplyclass_linux.go#L17-L53","documentation":"The Linux power_supply_class collector's Update calls getPowerSupplyClassInfo; if it fails with an error other than os.ErrNotExist, the scrape is aborted with \"could not get power_supply class info\". os.ErrNotExist is deliberately translated to ErrNoData (a benign no-data scrape) — this wrapped error is the genuine-failure path, meaning /sys/class/power_supply exists but could not be read.","triggerScenarios":"Update -> getPowerSupplyClassInfo returning a non-ErrNotExist error, e.g. procfs failing to read /sys/class/power_supply entries due to permission problems or I/O errors on the sysfs files.","commonSituations":"node_exporter running in a container without the host's /sys mounted (partial mount or masked paths); restricted read permissions on /sys/class/power_supply; kernel without power_supply support producing unexpected sysfs states.","solutions":["Verify /sys/class/power_supply is readable by the exporter user; add read permissions or run with adequate privileges.","In containers, mount the host sysfs read-only: -v /sys:/host/sys:ro and set --path.sysfs=/host/sys.","If the machine genuinely has no power supplies, confirm the error is os.ErrNotExist (which yields ErrNoData, not this error) and disable --collector.powersupplyclass."],"exampleFix":"// before\ndocker run node-exporter  # /sys not mounted\n// after\ndocker run -v /sys:/host/sys:ro node-exporter --path.sysfs=/host/sys","handlingStrategy":"fallback","validationCode":"// Pre-flight check before enabling the collector\nif _, err := os.Stat(\"/sys/class/power_supply\"); err != nil {\n\tif os.IsNotExist(err) {\n\t\tlogger.Info(\"no power_supply class; disabling collector\")\n\t}\n}","typeGuard":null,"tryCatchPattern":"// Map ErrNoData to a clean scrape, otherwise surface the wrapped error.\nif err := coll.Update(ch); err != nil {\n\tif errors.Is(err, ErrNoData) {\n\t\treturn nil\n\t}\n\tlogger.Error(\"powersupplyclass scrape failed\", \"err\", err)\n\treturn err\n}","preventionTips":["Mount host /sys read-only into containers and point --path.sysfs at it.","Ensure the exporter user can read /sys/class/power_supply.","Disable --collector.powersupplyclass on machines without batteries/AC drivers."],"tags":["go","linux","sysfs","powersupply","node-exporter"],"backgroundTag":"file-read-failed","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}