{"record":{"id":"f57fd0726f70d1df","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-parse-voltage-now","errorCode":null,"errorMessage":"unable to parse voltage_now","messagePattern":"unable to parse voltage_now","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/runtime/battery/battery_linux.go","lineNumber":109,"sourceCode":"\tif len(bFiles) == 0 {\n\t\treturn nil, &NoBatteryError{}\n\t}\n\n\treturn bFiles, nil\n}\n\nfunc getByPath(path string) (*battery, error) {\n\tb := &battery{}\n\tvar err error\n\n\tif b.Current, err = readFloat(path, \"energy_now\"); err == nil {\n\t\tif b.Full, err = readFloat(path, \"energy_full\"); err != nil {\n\t\t\treturn nil, errors.New(\"unable to parse energy_full\")\n\t\t}\n\t} else {\n\t\tcurrentDoesNotExist := os.IsNotExist(err)\n\t\tif b.Voltage, err = readFloat(path, \"voltage_now\"); err != nil {\n\t\t\treturn nil, errors.New(\"unable to parse voltage_now\")\n\t\t}\n\t\tb.Voltage /= 1000\n\t\tif currentDoesNotExist {\n\t\t\tif b.Current, err = readAmp(path, \"charge_now\", b.Voltage); err != nil {\n\t\t\t\treturn nil, errors.New(\"unable to parse charge_now\")\n\t\t\t}\n\t\t\tif b.Full, err = readAmp(path, \"charge_full\", b.Voltage); err != nil {\n\t\t\t\treturn nil, errors.New(\"unable to parse charge_full\")\n\t\t\t}\n\t\t} else {\n\t\t\tif b.Full, err = readFloat(path, \"energy_full\"); err != nil {\n\t\t\t\treturn nil, errors.New(\"unable to parse energy_full\")\n\t\t\t}\n\t\t}\n\t}\n\n\tstate, err := os.ReadFile(filepath.Join(path, \"status\"))\n\tif err != nil || len(state) == 0 {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/battery/battery_linux.go#L91-L127","documentation":"On Linux the battery package reads sysfs files under /sys/class/power_supply/<bat>/. When energy_now is missing (or unparseable) it falls back to voltage-based charge reporting, reading voltage_now via readFloat. If that read fails (file missing, empty, or containing a non-numeric value) getByPath aborts with 'unable to parse voltage_now'.","triggerScenarios":"battery.Get()/systemGetAll -> getByPath on a Linux sysfs battery whose energy_now read failed AND whose voltage_now file is absent, empty, or non-numeric.","commonSituations":"Virtualized/containerized environments exposing a partial power_supply node (e.g. a USB HID UPS or a virtual battery without voltage_now); exotic hardware or driver exposing only charge_* or energy_* but not voltage_now; sysfs mounted read-only or filtered.","solutions":["Check that /sys/class/power_supply/<bat>/voltage_now exists and contains an integer (microvolts): cat /sys/class/power_supply/BAT0/voltage_now","If the node is not a real battery (UPS, HID device, virtual supply), exclude it or fix the driver so type is not 'Battery' or files are complete","If running in a VM/container, remove the synthetic power_supply entry or bind-mount a complete one","Fall back to handling the returned error and treating the segment as no-battery"],"exampleFix":"// before (debugging shell)\ncat /sys/class/power_supply/BAT0/voltage_now  # cat: ...: No such file or directory\n// after (verify a complete node or pick a real battery)\nls /sys/class/power_supply/BAT0/{voltage_now,charge_now,charge_full,status}","handlingStrategy":"fallback","validationCode":"const files = ['energy_now','voltage_now'];\nfor (const f of files) {\n  try { const v = await Deno.readTextFile(`/sys/class/power_supply/BAT0/${f}`); if (!v.trim()) throw new Error(f); } catch { /* fall back */ }\n}","typeGuard":"func hasVoltageNow(dir string) bool {\n  b, err := os.ReadFile(filepath.Join(dir, \"voltage_now\"))\n  return err == nil && len(strings.TrimSpace(string(b))) > 0\n}","tryCatchPattern":"bat, err := battery.Get()\nif err != nil {\n  var noBat *battery.NoBatteryError\n  if !errors.As(err, &noBat) { log.Printf(\"battery read failed: %v\", err) }\n  // render prompt without battery info\n}","preventionTips":["Check /sys/class/power_supply nodes exist and are complete before enabling a battery segment","In VMs/containers, disable the battery segment or bind-mount complete power_supply nodes","Treat battery errors as non-fatal and hide the segment"],"tags":["linux","sysfs","battery","file-not-found"],"backgroundTag":"sysfs-battery-file-missing","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}