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

  1. Verify: cat /sys/class/power_supply/BAT0/status (expect e.g. 'Discharging'); check permissions if it fails
  2. Update the kernel/driver so status is populated
  3. Exclude the non-conforming power_supply node
  4. 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

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

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/da72d44f8997e58f. Report an issue: GitHub.