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

Overflow panic when pretty printing Battery struct. #14

Closed bddap closed 5 years ago

bddap commented 5 years ago

Setup:

fn main() {
    let batteries = battery::Manager::new().iter().collect::<Vec<_>>();
    println!("{:#?}", batteries);
}

Error 😨:

[
    Battery {
        vendor: Some(
            "SMP"
        ),
        model: Some(
            "bq20z451"
        ),
        serial_number: Some(
            "D866466Q2BPFWLKFQ"
        ),
        technology: Unknown,
        state: Full,
        capacity: 0.0,
        temperature: Some(
            30.11
thread 'main' panicked at 'attempt to multiply with overflow', /Users/a/.cargo/registry/src/github.com-1ecc6299db9ec823/battery-0.6.0/src/platform/macos/device.rs:128:10
note: Run with `RUST_BACKTRACE=1` for a backtrace.
        )

OS: macOS High Sierra 10.13.6 17G5019 x86_64 Host: MacBookPro11,4

bddap commented 5 years ago

Nice crate btw.

svartalf commented 5 years ago

Thanks :)

Are you using version from the crates.io or from the github? I think this was fixed in #10, but was not published yet.

bddap commented 5 years ago

I was using the version on crates.io.

svartalf commented 5 years ago

Any chance you can test latest master?

bddap commented 5 years ago

Master works fine:

[
    Battery {
        vendor: Some(
            "SMP"
        ),
        model: Some(
            "bq20z451"
        ),
        serial_number: Some(
            "D866466Q2BPFWLKFQ"
        ),
        technology: Unknown,
        state: Full,
        capacity: 0.0,
        temperature: Some(
            30.17
        ),
        percentage: 99.36493,
        cycle_count: Some(
            112
        ),
        energy: 105011352,
        energy_full: 105682516,
        energy_full_design: 113000785,
        energy_rate: 0,
        voltage: 12907,
        time_to_full: None,
        time_to_empty: None
    }
]
svartalf commented 5 years ago

Yay! Unfortunately, I see that you are also affected by #8 bug, so I'll leave this issue opened for a while.

Going to try to fix it tomorrow and post a comment here.

svartalf commented 5 years ago

Since #8 was closed, I'm closing this issue too.

Fixed versions were published to crates.io