1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-27 17:07:44 +00:00

battery: bettery error handling in sysfs value reading

This commit is contained in:
NotAShelf 2025-05-16 04:03:08 +03:00
parent 6c2fc6652f
commit a3137ff2d0
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF

View file

@ -167,10 +167,12 @@ fn read_sysfs_value(path: impl AsRef<Path>) -> Result<String> {
fs::read_to_string(p)
.map_err(|e| {
let error_msg = format!("Path: {:?}, Error: {}", p.display(), e);
if e.kind() == io::ErrorKind::PermissionDenied {
ControlError::PermissionDenied(error_msg)
} else {
ControlError::ReadError(error_msg)
match e.kind() {
io::ErrorKind::PermissionDenied => ControlError::PermissionDenied(error_msg),
io::ErrorKind::NotFound => {
ControlError::PathMissing(format!("Path '{}' does not exist", p.display()))
}
_ => ControlError::ReadError(error_msg),
}
})
.map(|s| s.trim().to_string())
@ -220,7 +222,6 @@ fn apply_thresholds_to_batteries(
let stop_path = battery.path.join(battery.pattern.stop_path);
// Read current thresholds in case we need to restore them
let current_start = read_sysfs_value(&start_path).ok();
let current_stop = read_sysfs_value(&stop_path).ok();
// Write stop threshold first (must be >= start threshold)