JanDeDobbeleer/oh-my-posh · error
unable to parse or invalid status
Error message
unable to parse or invalid status
What it means
Every Linux battery must expose a status file whose content is mapped to a State. If the status file cannot be read or is empty, getByPath returns 'unable to parse or invalid status'.
Source
Thrown at src/runtime/battery/battery_linux.go:128
}
b.Voltage /= 1000
if currentDoesNotExist {
if b.Current, err = readAmp(path, "charge_now", b.Voltage); err != nil {
return nil, errors.New("unable to parse charge_now")
}
if b.Full, err = readAmp(path, "charge_full", b.Voltage); err != nil {
return nil, errors.New("unable to parse charge_full")
}
} else {
if b.Full, err = readFloat(path, "energy_full"); err != nil {
return nil, errors.New("unable to parse energy_full")
}
}
}
state, err := os.ReadFile(filepath.Join(path, "status"))
if err != nil || len(state) == 0 {
return nil, errors.New("unable to parse or invalid status")
}
if b.State, err = newState(string(state[:len(state)-1])); err != nil {
return nil, errors.New("unable to map to new state")
}
return b, nil
}
func systemGetAll() ([]*battery, error) {
bFiles, err := getBatteryFiles()
if err != nil {
return nil, err
}
var batteries []*battery
var errs Errors
for _, bFile := range bFiles {View on GitHub (pinned to 0976794618)
Solutions
- Verify: cat /sys/class/power_supply/BAT0/status (expect e.g. 'Discharging'); check permissions if it fails
- Update the kernel/driver so status is populated
- Exclude the non-conforming power_supply node
- Handle the error as unknown/absent battery state in the caller
Example fix
// before $ cat /sys/class/power_supply/BAT0/status (empty) // after $ cat /sys/class/power_supply/BAT0/status Discharging
Defensive patterns
Strategy: validation
Validate before calling
status=$(cat /sys/class/power_supply/BAT0/status 2>/dev/null); [ -n "$status" ] || echo "status missing - battery segment will fail"
Type guard
func hasStatus(dir string) bool {
b, err := os.ReadFile(filepath.Join(dir, "status"))
return err == nil && len(b) > 0
} Try / catch
bat, err := battery.Get()
if err != nil {
log.Printf("battery status unavailable: %v", err)
return nil
} Prevention
- Confirm status is populated before enabling the battery segment
- Update kernel/driver when status is never written
- Exclude power_supply nodes that do not conform to the standard ABI
When it happens
Trigger: battery.Get()/systemGetAll -> getByPath where os.ReadFile(<bat>/status) errors or returns zero bytes.
Common situations: Driver hides or never populates status; sysfs permissions/container restrictions; empty status read from a flaky embedded controller.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unable to parse energy_full
- unable to parse voltage_now
- unable to parse charge_now
- unable to parse charge_full
- unable to map to new state
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/da72d44f8997e58f.
Report an issue: GitHub.