diff --git a/src/config.rs b/src/config.rs index cc9f18c..5d528b8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 { diff --git a/src/cpu.rs b/src/cpu.rs index 4d9d551..ceac01d 100644 --- a/src/cpu.rs +++ b/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; diff --git a/src/power_supply.rs b/src/power_supply.rs index 9ec00ab..12649b8 100644 --- a/src/power_supply.rs +++ b/src/power_supply.rs @@ -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"))?