1
Fork 0
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:
RGBCube 2025-05-19 21:44:27 +03:00
parent ca4b1dbc92
commit b6d4e09c7f
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M
3 changed files with 13 additions and 11 deletions

View file

@ -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 {

View file

@ -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;

View file

@ -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"))?