diff --git a/src/cli/debug.rs b/src/cli/debug.rs index b8834e1..eeed61f 100644 --- a/src/cli/debug.rs +++ b/src/cli/debug.rs @@ -219,13 +219,15 @@ fn get_kernel_info() -> Result { /// Get system uptime fn get_system_uptime() -> Result { - let uptime_str = fs::read_to_string("/proc/uptime").map_err(AppError::Io)?; + let uptime_str = fs::read_to_string("/proc/uptime").map_err(|e| AppError::Io(e))?; let uptime_secs = uptime_str .split_whitespace() .next() - .ok_or_else(|| AppError::Generic("Invalid uptime format".to_string()))? + .ok_or_else(|| AppError::Generic("Invalid format in /proc/uptime file".to_string()))? .parse::() - .map_err(|e| AppError::Generic(format!("Failed to parse uptime: {e}")))?; + .map_err(|e| { + AppError::Generic(format!("Failed to parse uptime from /proc/uptime: {}", e)) + })?; Ok(Duration::from_secs_f64(uptime_secs)) } diff --git a/src/main.rs b/src/main.rs index 79188ad..8c717af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -402,9 +402,9 @@ fn main() -> Result<(), AppError> { error!( "Start threshold ({start_threshold}) must be less than stop threshold ({stop_threshold})" ); - Err(ControlError::InvalidValueError(format!( + Err(AppError::Generic(format!( "Start threshold ({start_threshold}) must be less than stop threshold ({stop_threshold})" - )).into()) + ))) } else { info!( "Setting battery thresholds: start at {start_threshold}%, stop at {stop_threshold}%" @@ -464,14 +464,15 @@ fn init_logger() { fn validate_freq(freq_mhz: u32, label: &str) -> Result<(), AppError> { if freq_mhz == 0 { error!("{label} frequency cannot be zero"); - Err(ControlError::InvalidValueError(format!("{label} frequency cannot be zero")).into()) + let err = ControlError::InvalidValueError(format!("{label} frequency cannot be zero")); + Err(err.into()) } else if freq_mhz > 10000 { // Extremely high value unlikely to be valid error!("{label} frequency ({freq_mhz} MHz) is unreasonably high"); - Err(ControlError::InvalidValueError(format!( + let err = ControlError::InvalidValueError(format!( "{label} frequency ({freq_mhz} MHz) is unreasonably high" - )) - .into()) + )); + Err(err.into()) } else { Ok(()) }