{"record":{"id":"765e80f26e98b4a3","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-map-to-new-state","errorCode":null,"errorMessage":"unable to map to new state","messagePattern":"unable to map to new state","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/runtime/battery/battery_linux.go","lineNumber":131,"sourceCode":"\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 {\n\t\treturn nil, errors.New(\"unable to parse or invalid status\")\n\t}\n\tif b.State, err = newState(string(state[:len(state)-1])); err != nil {\n\t\treturn nil, errors.New(\"unable to map to new state\")\n\t}\n\n\treturn b, nil\n}\n\nfunc systemGetAll() ([]*battery, error) {\n\tbFiles, err := getBatteryFiles()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar batteries []*battery\n\tvar errs Errors\n\n\tfor _, bFile := range bFiles {\n\t\tb, err := getByPath(bFile)\n\t\tif err != nil {\n\t\t\terrs = append(errs, err)","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/battery/battery_linux.go#L113-L149","documentation":"After reading status, the value is mapped through newState, which matches (case-insensitively) against the known states (Charging, Discharging, Full, NotCharging, Empty, Unknown...). An unrecognized status string produces 'unable to map to new state'.","triggerScenarios":"battery.Get()/systemGetAll -> getByPath where <bat>/status contains a string not in the known state list (the trailing newline is stripped before mapping).","commonSituations":"Kernel exposing vendor-specific status strings (e.g. 'Idle', 'Garbage'); locale/whitespace oddities from a patched kernel; new ACPI state string on an old library version.","solutions":["Inspect the raw value: cat /sys/class/power_supply/BAT0/status | xxd | tail","Update the library/kernel so the status string is a recognized standard value","Patch or wrap newState to map vendor strings to the closest known state","Treat the error as unknown state in the caller"],"exampleFix":"// before\n$ cat /sys/class/power_supply/BAT0/status\nIdle\n// after (recognized value or updated mapping)\n$ cat /sys/class/power_supply/BAT0/status\nNot charging","handlingStrategy":"validation","validationCode":"case \"$(cat /sys/class/power_supply/BAT0/status 2>/dev/null)\" in\n  Charging|Discharging|Full|\"Not charging\"|Empty|Unknown) ;;\n  *) echo \"unrecognized status - will fail state mapping\" ;;\nesac","typeGuard":"func knownStatus(s string) bool {\n  for _, st := range []string{\"Charging\", \"Discharging\", \"Full\", \"Not charging\", \"Empty\", \"Unknown\"} {\n    if strings.EqualFold(strings.TrimSpace(s), st) { return true }\n  }\n  return false\n}","tryCatchPattern":"bat, err := battery.Get()\nif err != nil {\n  log.Printf(\"battery state unmapped: %v\", err)\n  return nil\n}","preventionTips":["Check raw status strings (xxd) on vendor kernels before relying on state","Keep the library updated for new ACPI status values","Map vendor-specific strings to known states in a wrapper"],"tags":["linux","battery","state-mapping","parse-error"],"backgroundTag":"battery-status-unmapped","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}