mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
power_supply&cpu: somewhat improve error messages
This commit is contained in:
parent
ca4b1dbc92
commit
b6d4e09c7f
3 changed files with 13 additions and 11 deletions
|
@ -60,7 +60,7 @@ impl CpuDelta {
|
|||
|
||||
cpus
|
||||
}
|
||||
None => cpu::Cpu::all()?,
|
||||
None => cpu::Cpu::all().context("failed to get all CPUs and their information")?,
|
||||
};
|
||||
|
||||
for cpu in cpus {
|
||||
|
|
11
src/cpu.rs
11
src/cpu.rs
|
@ -92,10 +92,13 @@ impl Cpu {
|
|||
|
||||
/// Rescan CPU, tuning local copy of settings.
|
||||
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
||||
let has_cpufreq = exists(format!(
|
||||
"/sys/devices/system/cpu/cpu{number}/cpufreq",
|
||||
number = self.number,
|
||||
));
|
||||
let Self { number, .. } = self;
|
||||
|
||||
if !exists(format!("/sys/devices/system/cpu/cpu{number}")) {
|
||||
bail!("{self} does not exist");
|
||||
}
|
||||
|
||||
let has_cpufreq = exists(format!("/sys/devices/system/cpu/cpu{number}/cpufreq"));
|
||||
|
||||
self.has_cpufreq = has_cpufreq;
|
||||
|
||||
|
|
|
@ -62,12 +62,7 @@ pub struct PowerSupply {
|
|||
|
||||
impl fmt::Display for PowerSupply {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"power supply '{name}' at '{path}'",
|
||||
name = &self.name,
|
||||
path = self.path.display(),
|
||||
)?;
|
||||
write!(f, "power supply '{name}'", name = &self.name)?;
|
||||
|
||||
if let Some(config) = self.threshold_config.as_ref() {
|
||||
write!(
|
||||
|
@ -147,6 +142,10 @@ impl PowerSupply {
|
|||
}
|
||||
|
||||
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
||||
if !self.path.exists() {
|
||||
bail!("{self} does not exist");
|
||||
}
|
||||
|
||||
let threshold_config = self
|
||||
.get_type()
|
||||
.with_context(|| format!("failed to determine what type of power supply '{self}' is"))?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue