starship / starship

☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell!
https://starship.rs
ISC License
44.63k stars 1.94k forks source link

`battery` module warning on desktop macOS 12 #2800

Closed marcofeltmann closed 2 years ago

marcofeltmann commented 3 years ago

Current Behavior

starship inside zsh configured via ohmyzsh shows the following warning:

[WARN] - (starship::modules::battery): Unable to access battery information:
FullyCharged

Expected Behavior

No warning expected

Additional context/Screenshots

Bildschirmfoto 2021-06-14 um 18 23 07

Possible Solution

Temporarily disabled battery information since the Mac Mini does not have batteries anyway. May happen on MacBook Pro M1 w/ macOS 12 beta as well…

Environment

# Keep system path before adding stuff to user path
SYSPATH=$PATH

# Adds Go Tools to path
PATH=/Users/marcofeltmann/go/bin:

# Adds Android Tooling to path
PATH+=/Users/marcofeltmann/sysroots/Android/sdk/tools:/Users/marcofeltmann/sysroots/Android/sdk/platform-tools:

# Append system path and export it eventually.
PATH+=$SYSPATH
export PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/marcofeltmann/.oh-my-zsh"

ZSH_THEME="robbyrussell"

plugins=(git)

source $ZSH/oh-my-zsh.sh

eval "$(starship init zsh)"

Starship Configuration

<no config>
kidonng commented 3 years ago

May happen on MacBook Pro M1 w/ macOS 12 beta as well…

I'm also on beta and have no issue. OS is no related.

image

Expected Behavior

No warning expected

Technically speaking, the warning is expected.

Temporarily disabled battery information since the Mac Mini does not have batteries anyway.

We can't tell whether you system does not have batteries or something goes wrong. Only thing we can do is to silence the message, but that's not good. Or you can disable the battery module.

matchai commented 3 years ago

Can you please share your starship logs where you encounter the error:

STARSHIP_LOG=trace starship prompt

Most of the heavy-lifting for the battery module is done by svartalf/rust-battery, so this may require an upstream issue to be created if we're receiving an unparsable output on M1 desktop machines.

egoist commented 3 years ago

here's the related debug logs:

[DEBUG] - (starship::utils): Error reading file: Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[TRACE] - (starship::utils): Trying to read from "/Users/egoist/vpkg.json"
[WARN] - (starship::modules::battery): Unable to access battery information:
FullyCharged
[TRACE] - (starship::utils): Executing command "git" with args ["-C", "/Users/egoist", "--no-optional-locks", "stash", "list"]
[DEBUG] - (starship::utils): Error reading file: Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })
[TRACE] - (starship::modules): Took 5.426666ms to compute module "package"
[TRACE] - (starship::config): No config found for "package": Option "package" not found
[TRACE] - (starship::modules): Took 620.916µs to compute module "battery"
matchai commented 3 years ago

Heya EGOIST 👋 Thanks for the logs. Unfortunately, it doesn't look like there's a whole lot else to work with.

What's unusual is that it seems rust-battery provides us with an Error, though we still get a sensible battery state of FullyCharged, which doesn't seem like something I remember seeing on other desktop machines. 🤔 If this appears as a unique combination on M1 desktop machines, perhaps we can specifically handle this case differently.

dmd commented 2 years ago

This happens for me on Monterey on an M1 Imac.

mogita commented 2 years ago

It happens for me too on Monterey 12.0.1 on an M1 iMac 2021. Starship version 0.58.0. zsh version 5.8 (x86_64-apple-darwin21.0).

nomaed commented 2 years ago

Can confirm the same on Mac mini (M1, 2020) after the upgrade.

I am not familiar with the codebase, but is it possible to add an exception so that an Error of "FullyCharged" will be treated like no error?

mogita commented 2 years ago

For the machines without a battery, you can disable the feature with starship config battery.disabled true.

Source: https://github.com/starship/starship/issues/1940#issuecomment-735273755

kidonng commented 2 years ago

As mentioned by @matchai the heavy lifting is done by the battery crate, so it's best to open an issue there and ask for help.

If this warning does not appear on previous versions of macOS then it's Apple changing stuff. The code for darwin platform in battery crate hasn't been updated for over a year, probably that's the issue.

For now the best thing you can do is to disable the battery module on machines without a battery, as commented in https://github.com/starship/starship/issues/2800#issuecomment-951956393.

horasal commented 2 years ago

It seems that fully_charged and designed_capacity are missing on recent macOS so I opened a PR https://github.com/svartalf/rust-battery/pull/93/files avoiding rust-battery throws errors when these two keys are empty.