JanDeDobbeleer/oh-my-posh · info

no battery found

Error message

no battery found

What it means

BatteryState on macOS runs `pmset -g batt` and requires the word 'Battery' to appear in the output. When it does not, the machine has no battery (or the battery line is absent), and this error is returned before attempting any parsing. It is the normal path for desktops (Mac mini, Mac Studio, Hackintosh) and VMs.

Source

Thrown at src/runtime/terminal_darwin.go:61

	if percentage, err = strconv.Atoi(matches["PERCENTAGE"]); err != nil {
		log.Error(err)
		return nil, errors.New("unable to parse battery percentage")
	}
	return &battery.Info{
		Percentage: percentage,
		State:      mapMostLogicalState(matches["STATE"]),
	}, nil
}

func (term *Terminal) BatteryState() (*battery.Info, error) {
	defer log.Trace(time.Now())
	output, err := term.RunCommand("pmset", "-g", "batt")
	if err != nil {
		log.Error(err)
		return nil, err
	}
	if !strings.Contains(output, "Battery") {
		return nil, errors.New("no battery found")
	}
	return term.parseBatteryOutput(output)
}

View on GitHub (pinned to 0976794618)

Solutions

  1. Hide the battery segment (e.g. only enable it on laptops or when the battery is present).
  2. Run `pmset -g batt` to confirm the machine really has no battery line.
  3. Ignore the error if you build on the environment API — treat it as 'no battery' rather than a failure.
  4. Check battery health in System Information if you expected one to be present.

Example fix

// before: battery segment always in prompt
{ "type": "battery", ... }
// after: only when a battery exists
{ "type": "battery", "display_mode": "images", ... } // segment already hides when error/no battery
Defensive patterns

Strategy: fallback

Validate before calling

// only render a battery segment when a battery exists
out, _ := exec.Command("pmset", "-g", "batt").Output()
hasBattery := strings.Contains(string(out), "Battery")

Try / catch

state, err := env.BatteryState()
if err != nil {
    state = nil // no battery: skip segment
}

Prevention

When it happens

Trigger: BatteryState called on a machine whose `pmset -g batt` output lacks a 'Battery' line — no battery hardware, battery removed/disabled, or pmset reporting only AC power source lines.

Common situations: Desktop Macs and Hackintoshes; macOS VMs; laptops with a failed/removed battery; running pmset in contexts where battery info is unavailable.

Related errors


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