JanDeDobbeleer/oh-my-posh · error
unknown value received
Error message
unknown value received
What it means
On Windows, systemGetAll calls Win32 GetSystemPowerStatus. When BatteryLifePercent is 0xFF (255) the OS is saying the percentage is unknown (e.g. no battery or transient state), so the library errors with 'unknown value received'.
Source
Thrown at src/runtime/battery/battery_windows.go:75
var getSystemPowerStatus = kernel32.NewProc("GetSystemPowerStatus")
func systemGetAll() ([]*battery, error) {
var sps systemPowerStatus
r1, _, errno := syscall.SyscallN(getSystemPowerStatus.Addr(), uintptr(unsafe.Pointer(&sps)))
if r1 == 0 {
if errno != 0 {
return nil, error(errno)
}
return nil, syscall.EINVAL
}
if sps.BatteryFlag&batteryFlagNoBattery != 0 || sps.BatteryFlag == batteryFlagUnknown {
return nil, &NoBatteryError{}
}
if sps.BatteryLifePercent == batteryLifePercentUnknown {
return nil, errors.New("unknown value received")
}
b := &battery{Full: 100, Current: float64(min(sps.BatteryLifePercent, 100))}
switch {
case sps.BatteryFlag&batteryFlagCharging != 0:
b.State = Charging
case sps.BatteryLifePercent == 100 && sps.ACLineStatus == acLineOnline:
b.State = Full
case sps.ACLineStatus == acLineOnline:
b.State = NotCharging
case sps.BatteryFlag&batteryFlagCritical != 0:
b.State = Empty
default:
b.State = Discharging
}
return []*battery{b}, nilView on GitHub (pinned to 0976794618)
Solutions
- Confirm a real battery exists (powercfg /batteryreport or Get-WmiObject Win32_Battery); if none, expect NoBatteryError instead
- Retry after a moment - the value can be transiently unknown after resume/suspend
- Update BIOS/battery drivers so Windows can report the percentage
- Handle the error gracefully and hide the battery segment
Example fix
null
Defensive patterns
Strategy: try-catch
Validate before calling
$sps = [System.Windows.Forms.SystemInformation]::PowerStatus
if ($sps.BatteryLifePercent -eq 255) { 'percentage unknown - segment will error' } Try / catch
bat, err := battery.Get()
if err != nil {
log.Printf("battery percentage unknown: %v", err)
return nil // hide battery segment
} Prevention
- Check Win32_Battery / powercfg /batteryreport to confirm a real battery exists
- Retry after resume - BatteryLifePercent can be transiently 0xFF
- Update BIOS/battery drivers when percent stays unknown
When it happens
Trigger: battery.Get()/systemGetAll on Windows when SYSTEM_POWER_STATUS.BatteryLifePercent == 255 (batteryFlag passed the no-battery checks but percent is still unknown).
Common situations: Desktops/VMs with a marginal battery detection race; UPS devices where Windows reports unknown percent; some laptops right after resume or with failing battery firmware; Hyper-V guests.
Related errors
- unable to add font resource using AddFontResourceW
- unable to open window process
- no matching window title found
- unable to delete font file after registry key open error
- unable to open HKEY_CURRENT_USER
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/a98ba27c8053f0ae.
Report an issue: GitHub.