Macchina-CLI / macchina

A system information frontend with an emphasis on performance.
https://crates.io/crates/macchina
MIT License
1.41k stars 51 forks source link

[BUG] Crashes on cpu model "Intel Core i7 9xx (Nehalem Core i7, IBRS update)" #277

Closed yonas closed 1 year ago

yonas commented 1 year ago
❯ RUST_BACKTRACE=full macchina
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error(Utf8Error { valid_up_to: 48, error_len: Some(1) })', /home/yonas/.cargo/registry/src/github.com-1ecc6299db9ec823/libmacchina-6.3.5/src/freebsd/mod.rs:245:14
stack backtrace:
   0:      0x95c60dc668c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he71fd4eda74f87b0
   1:      0x95c60d75b8e - core::fmt::write::h5fd3e26984166a6e
   2:      0x95c60da9fc4 - std::io::Write::write_fmt::h69fa03c5d51d5c91
   3:      0x95c60dc6457 - std::sys_common::backtrace::print::h05788f88478cef7c
   4:      0x95c60daa785 - std::panicking::default_hook::{{closure}}::h0a304c2f161776d3
   5:      0x95c60dab044 - std::panicking::rust_panic_with_hook::h2b720056ea930d75
   6:      0x95c60dc6ae4 - std::panicking::begin_panic_handler::{{closure}}::h9b43afdf57796039
   7:      0x95c60dc6a4c - std::sys_common::backtrace::__rust_end_short_backtrace::he531317bc19f7b93
   8:      0x95c60daa9b1 - rust_begin_unwind
   9:      0x95c60d777f2 - core::panicking::panic_fmt::hf50430e1e32891db
  10:      0x95c60d77c12 - core::result::unwrap_failed::ha57a5a37c8028fff
  11:      0x95c60cf0415 - macchina::data::get_all_readouts::ha941b43deae04036
  12:      0x95c60cd61f4 - macchina::main::h0b3d4ee83dd19d37
  13:      0x95c60ccf1b3 - std::sys_common::backtrace::__rust_begin_short_backtrace::h66494afa16fca70b
  14:      0x95c60ccfc0c - main

yonas in 🌐 server1 in make-cd on  master via C v13.0.0-clang via 🐹 v1.20.2 via 🌙 via 👑 via  v18.13.0 via 🐍 v3.9.16 via V v0.3.3 via ↯ 

❯ sysctl hw.model
hw.model: Intel Core i7 9xx (Nehalem Core i7, IBRS update)

❯ macchina --doctor
Let's check your system for errors... Here's a summary:

We've collected 18 readouts, including 11 failed read(s) and 1 read(s) which resulted in a warning.
Readout "Machine" failed with message: Metric is not available on this system.
Readout "Kernel" failed with message: Metric is not available on this system.
Readout "Distribution" failed with message: Metric is not available on this system.
Readout "OperatingSystem" failed with message: Metric is not available on this system.
Readout "DesktopEnvironment" failed with message: You appear to be only running a window manager.
Readout "WindowManager" failed with message: "wmctrl" must be installed to display your window manager.
Readout "Terminal" failed with message: Could not to fetch terminal.
Readout "LocalIP" failed with message: Unable to get local IPv4 address.
Readout "Backlight" failed with message: Metric is not available on this system.
Readout "Uptime" failed with message: Metric is not available on this system.
Readout "Battery" failed with message: Metric is not available on this system.

1 of the 12 unsuccessful read(s) resulted in a warning:
Readout "Resolution" threw a warning with message: Could not open a connection to the X11 server.
grtcdr commented 1 year ago

It looks like sysctl hw.model may have returned an ill-formatted byte which led to the panic. I'm working on fixing this.

grtcdr commented 1 year ago

I went and wrapped the value_string invocation using our own ReadoutError which will propagate to macchina in a safe way. The panic should no longer occur and --doctor will show us an error message that may or may not help.

yonas commented 1 year ago
❯ RUST_BACKTRACE=full target/release/macchina --doctor
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error(Utf8Error { valid_up_to: 48, error_len: Some(1) })', /home/yonas/.cargo/registry/src/github.com-1ecc6299db9ec823/libmacchina-6.4.0/src/freebsd/mod.rs:245:14
stack backtrace:
   0:     0x32a3d53dd75c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he71fd4eda74f87b0
   1:     0x32a3d535696e - core::fmt::write::h5fd3e26984166a6e
   2:     0x32a3d53c30b4 - std::io::Write::write_fmt::h69fa03c5d51d5c91
   3:     0x32a3d53dd537 - std::sys_common::backtrace::print::h05788f88478cef7c
   4:     0x32a3d53c3885 - std::panicking::default_hook::{{closure}}::h0a304c2f161776d3
   5:     0x32a3d53c4194 - std::panicking::rust_panic_with_hook::h2b720056ea930d75
   6:     0x32a3d53ddbb4 - std::panicking::begin_panic_handler::{{closure}}::h9b43afdf57796039
   7:     0x32a3d53ddb1c - std::sys_common::backtrace::__rust_end_short_backtrace::he531317bc19f7b93
   8:     0x32a3d53c3b01 - rust_begin_unwind
   9:     0x32a3d53586d2 - core::panicking::panic_fmt::hf50430e1e32891db
  10:     0x32a3d5358ae2 - core::result::unwrap_failed::ha57a5a37c8028fff
  11:     0x32a3d5377a4c - macchina::data::get_all_readouts::hef727af34dbb0250
  12:     0x32a3d53692e3 - macchina::main::h9baa4fd3d260d27c
  13:     0x32a3d5365059 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd5483f5276f70cc0
  14:     0x32a3d53656c9 - main

❯ RUST_BACKTRACE=full target/release/macchina
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error(Utf8Error { valid_up_to: 48, error_len: Some(1) })', /home/yonas/.cargo/registry/src/github.com-1ecc6299db9ec823/libmacchina-6.4.0/src/freebsd/mod.rs:245:14
stack backtrace:
   0:     0x149b30c6d75c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he71fd4eda74f87b0
   1:     0x149b30be696e - core::fmt::write::h5fd3e26984166a6e
   2:     0x149b30c530b4 - std::io::Write::write_fmt::h69fa03c5d51d5c91
   3:     0x149b30c6d537 - std::sys_common::backtrace::print::h05788f88478cef7c
   4:     0x149b30c53885 - std::panicking::default_hook::{{closure}}::h0a304c2f161776d3
   5:     0x149b30c54194 - std::panicking::rust_panic_with_hook::h2b720056ea930d75
   6:     0x149b30c6dbb4 - std::panicking::begin_panic_handler::{{closure}}::h9b43afdf57796039
   7:     0x149b30c6db1c - std::sys_common::backtrace::__rust_end_short_backtrace::he531317bc19f7b93
   8:     0x149b30c53b01 - rust_begin_unwind
   9:     0x149b30be86d2 - core::panicking::panic_fmt::hf50430e1e32891db
  10:     0x149b30be8ae2 - core::result::unwrap_failed::ha57a5a37c8028fff
  11:     0x149b30c07a4c - macchina::data::get_all_readouts::hef727af34dbb0250
  12:     0x149b30bf92e3 - macchina::main::h9baa4fd3d260d27c
  13:     0x149b30bf5059 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd5483f5276f70cc0
  14:     0x149b30bf56c9 - main
grtcdr commented 1 year ago

Did you point the libmacchina dependency to its git branch?

Something like:

# Cargo.toml
libmacchina = { git = "https://github.com/Macchina-CLI/libmacchina" }
yonas commented 1 year ago

@grtcdr After updating Cargo.toml, I get this compile error:

   Compiling macchina v6.1.8 (/usr/home/yonas/git/make-cd/files/macchina)
error[E0425]: cannot find function `version` in crate `libmacchina`
   --> src/main.rs:118:46
    |
118 |     println!("libmacchina  {}", libmacchina::version());
    |                                              ^^^^^^^ not found in `libmacchina`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `macchina` due to previous error

I didn't get this error for pfetch-rs after updating its Cargo.toml.

grtcdr commented 1 year ago

Sorry about this.

You should also enable the version feature.

libmacchina = { git = "https://github.com/Macchina-CLI/libmacchina", features = ["version"] }
yonas commented 1 year ago

It works now, thanks!