svartalf / rust-battery

Rust crate providing cross-platform information about the notebook batteries.
https://crates.io/crates/battery
Apache License 2.0
354 stars 40 forks source link

UTF error on NixOS #85

Closed ciarandg closed 3 years ago

ciarandg commented 3 years ago

When running the example code from the readme on NixOS 20.09, I get the following output: Error: Error { source: Custom { kind: InvalidData, error: "stream did not contain valid UTF-8" }, description: None }

I have seen the issue magically fix itself on reboot twice now, but cannot reproduce that behaviour -- it seems to happen for no reason at all. This is on a ThinkPad X1 Extreme Gen 2, I've also tested the example code on Arch Linux on the same computer and it seems to work perfectly. No idea how to troubleshoot this, I'm not particularly knowledgeable about rust (I ran into the issue because rust-battery is a dependency of dwm-status). NixOS has a pretty unique package manager that stores things at weird paths, so it might be related to that? Any help would be greatly appreciated.

Side note: I don't think this is related to #72 -- I tried using rust-battery as a local dependency after altering device.rs as described in the first post of that thread, but the error persisted.

ciarandg commented 3 years ago

Update: I think this is the same issue as #72 after all, the unpredictability seems to come from /sys/class/power_supply/BAT0/manufacturer and cat /sys/class/power_supply/BAT0/model_name occasionally being formatted in UTF-8 upon reboot but usually being scrambled as in #72. Very bizarre, if anyone knows why that might be happening I'd love to know. Will close the issue now since I figure the unpredictability means that there's probably something I can do to fix it outside of rust-battery