{"record":{"id":"40715d674e5441ec","repo":"JanDeDobbeleer/oh-my-posh","slug":"no-battery-found","errorCode":null,"errorMessage":"no battery found","messagePattern":"no battery found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/runtime/terminal_darwin.go","lineNumber":61,"sourceCode":"\tif percentage, err = strconv.Atoi(matches[\"PERCENTAGE\"]); err != nil {\n\t\tlog.Error(err)\n\t\treturn nil, errors.New(\"unable to parse battery percentage\")\n\t}\n\treturn &battery.Info{\n\t\tPercentage: percentage,\n\t\tState:      mapMostLogicalState(matches[\"STATE\"]),\n\t}, nil\n}\n\nfunc (term *Terminal) BatteryState() (*battery.Info, error) {\n\tdefer log.Trace(time.Now())\n\toutput, err := term.RunCommand(\"pmset\", \"-g\", \"batt\")\n\tif err != nil {\n\t\tlog.Error(err)\n\t\treturn nil, err\n\t}\n\tif !strings.Contains(output, \"Battery\") {\n\t\treturn nil, errors.New(\"no battery found\")\n\t}\n\treturn term.parseBatteryOutput(output)\n}\n","sourceCodeStart":43,"sourceCodeEnd":65,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/terminal_darwin.go#L43-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"Desktop Macs and Hackintoshes; macOS VMs; laptops with a failed/removed battery; running pmset in contexts where battery info is unavailable.","solutions":["Hide the battery segment (e.g. only enable it on laptops or when the battery is present).","Run `pmset -g batt` to confirm the machine really has no battery line.","Ignore the error if you build on the environment API — treat it as 'no battery' rather than a failure.","Check battery health in System Information if you expected one to be present."],"exampleFix":"// before: battery segment always in prompt\n{ \"type\": \"battery\", ... }\n// after: only when a battery exists\n{ \"type\": \"battery\", \"display_mode\": \"images\", ... } // segment already hides when error/no battery","handlingStrategy":"fallback","validationCode":"// only render a battery segment when a battery exists\nout, _ := exec.Command(\"pmset\", \"-g\", \"batt\").Output()\nhasBattery := strings.Contains(string(out), \"Battery\")","typeGuard":null,"tryCatchPattern":"state, err := env.BatteryState()\nif err != nil {\n    state = nil // no battery: skip segment\n}","preventionTips":["Add the battery segment only on laptops or gate it on battery presence.","Expect this error on desktop Macs, Hackintoshes, and VMs.","Use display modes/fold behavior so an absent battery renders nothing."],"tags":["macos","battery","hardware"],"backgroundTag":"no-battery-found","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}