{"record":{"id":"cafaeee7622d6676","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-parse-battery-percentage-cafaee","errorCode":null,"errorMessage":"unable to parse battery percentage","messagePattern":"unable to parse battery percentage","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/runtime/battery/battery_netbsd.go","lineNumber":18,"sourceCode":"package battery\n\nimport (\n\t\"errors\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd\"\n)\n\nfunc Get() (*Info, error) {\n\toutput, err := cmd.Run(\"envstat\", \"-s\", \"acpibat0:charge\", \"-n\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tpercentage, err := strconv.Atoi(strings.TrimSpace(output))\n\tif err != nil {\n\t\treturn nil, errors.New(\"unable to parse battery percentage\")\n\t}\n\treturn &Info{\n\t\tPercentage: percentage,\n\t\tState:      Unknown,\n\t}, nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/battery/battery_netbsd.go#L1-L25","documentation":"On NetBSD, battery info comes from running `envstat -s acpibat0:charge -n` and Atoi-ing the trimmed output. If envstat returns something that is not a bare integer, Get returns 'unable to parse battery percentage'.","triggerScenarios":"battery.Get() on NetBSD where `envstat -s acpibat0:charge -n` output does not Atoi-parse (units attached, labels, empty output, or acpibat0 absent).","commonSituations":"Machine with no acpibat0 device; envstat version printing values with units (e.g. '95.000') or headers; command output containing warnings on stderr merged in.","solutions":["Run `envstat -s acpibat0:charge -n` manually and check whether acpibat0 exists (sysctl hw or dmesg)","If no battery is present, treat the error as NoBattery rather than a parse failure","Normalize envstat output (strip units/labels) before Atoi, or parse floats and round","Update NetBSD/envstat or use an alternative sensor source"],"exampleFix":"// before\npercentage, err := strconv.Atoi(strings.TrimSpace(output))\n// after (tolerate values like \"95.000\")\npct, err := strconv.ParseFloat(strings.TrimSpace(output), 64)\nif err != nil { return nil, errors.New(\"unable to parse battery percentage\") }\npercentage := int(pct)","handlingStrategy":"fallback","validationCode":"out=$(envstat -s acpibat0:charge -n 2>/dev/null); case \"$out\" in ''|*[!0-9.]*) echo \"envstat output not a plain number - battery will fail\" ;; esac","typeGuard":null,"tryCatchPattern":"info, err := battery.Get()\nif err != nil {\n  log.Printf(\"battery unavailable: %v\", err)\n  return nil // render prompt without battery segment\n}","preventionTips":["Confirm acpibat0 exists (dmesg) before enabling the battery segment on NetBSD","Verify envstat output format on your NetBSD version","Detect no-battery machines and surface NoBatteryError instead of a parse error"],"tags":["netbsd","envstat","battery","parse-error"],"backgroundTag":"battery-percentage-parse-failed","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}