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

treewide: suppress clippy lint about Error suffix

This commit is contained in:
NotAShelf 2025-05-18 11:23:37 +03:00
parent 63cab6e631
commit fe93a50f9e
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF
3 changed files with 15 additions and 15 deletions

View file

@ -74,7 +74,7 @@ pub fn set_battery_charge_thresholds(start_threshold: u8, stop_threshold: u8) ->
// Validate thresholds using `BatteryChargeThresholds` // Validate thresholds using `BatteryChargeThresholds`
let thresholds = let thresholds =
BatteryChargeThresholds::new(start_threshold, stop_threshold).map_err(|e| match e { BatteryChargeThresholds::new(start_threshold, stop_threshold).map_err(|e| match e {
crate::config::types::ConfigError::ValidationError(msg) => { crate::config::types::ConfigError::Validation(msg) => {
ControlError::InvalidValueError(msg) ControlError::InvalidValueError(msg)
} }
_ => ControlError::InvalidValueError(format!("Invalid battery threshold values: {e}")), _ => ControlError::InvalidValueError(format!("Invalid battery threshold values: {e}")),

View file

@ -26,7 +26,7 @@ pub fn load_config_from_path(specific_path: Option<&str>) -> Result<AppConfig, C
if path.exists() { if path.exists() {
return load_and_parse_config(path); return load_and_parse_config(path);
} }
return Err(ConfigError::IoError(std::io::Error::new( return Err(ConfigError::Io(std::io::Error::new(
std::io::ErrorKind::NotFound, std::io::ErrorKind::NotFound,
format!("Specified config file not found: {}", path.display()), format!("Specified config file not found: {}", path.display()),
))); )));
@ -80,10 +80,10 @@ pub fn load_config_from_path(specific_path: Option<&str>) -> Result<AppConfig, C
/// Load and parse a configuration file /// Load and parse a configuration file
fn load_and_parse_config(path: &Path) -> Result<AppConfig, ConfigError> { fn load_and_parse_config(path: &Path) -> Result<AppConfig, ConfigError> {
let contents = fs::read_to_string(path).map_err(ConfigError::IoError)?; let contents = fs::read_to_string(path).map_err(ConfigError::Io)?;
let toml_app_config = let toml_app_config =
toml::from_str::<AppConfigToml>(&contents).map_err(ConfigError::TomlError)?; toml::from_str::<AppConfigToml>(&contents).map_err(ConfigError::Toml)?;
// Handle inheritance of values from global to profile configs // Handle inheritance of values from global to profile configs
let mut charger_profile = toml_app_config.charger.clone(); let mut charger_profile = toml_app_config.charger.clone();

View file

@ -23,17 +23,17 @@ pub struct BatteryChargeThresholds {
impl BatteryChargeThresholds { impl BatteryChargeThresholds {
pub fn new(start: u8, stop: u8) -> Result<Self, ConfigError> { pub fn new(start: u8, stop: u8) -> Result<Self, ConfigError> {
if stop == 0 { if stop == 0 {
return Err(ConfigError::ValidationError( return Err(ConfigError::Validation(
"Stop threshold must be greater than 0%".to_string(), "Stop threshold must be greater than 0%".to_string(),
)); ));
} }
if start >= stop { if start >= stop {
return Err(ConfigError::ValidationError(format!( return Err(ConfigError::Validation(format!(
"Start threshold ({start}) must be less than stop threshold ({stop})" "Start threshold ({start}) must be less than stop threshold ({stop})"
))); )));
} }
if stop > 100 { if stop > 100 {
return Err(ConfigError::ValidationError(format!( return Err(ConfigError::Validation(format!(
"Stop threshold ({stop}) cannot exceed 100%" "Stop threshold ({stop}) cannot exceed 100%"
))); )));
} }
@ -100,29 +100,29 @@ pub struct AppConfig {
// Error type for config loading // Error type for config loading
#[derive(Debug)] #[derive(Debug)]
pub enum ConfigError { pub enum ConfigError {
IoError(std::io::Error), Io(std::io::Error),
TomlError(toml::de::Error), Toml(toml::de::Error),
ValidationError(String), Validation(String),
} }
impl From<std::io::Error> for ConfigError { impl From<std::io::Error> for ConfigError {
fn from(err: std::io::Error) -> Self { fn from(err: std::io::Error) -> Self {
Self::IoError(err) Self::Io(err)
} }
} }
impl From<toml::de::Error> for ConfigError { impl From<toml::de::Error> for ConfigError {
fn from(err: toml::de::Error) -> Self { fn from(err: toml::de::Error) -> Self {
Self::TomlError(err) Self::Toml(err)
} }
} }
impl std::fmt::Display for ConfigError { impl std::fmt::Display for ConfigError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::IoError(e) => write!(f, "I/O error: {e}"), Self::Io(e) => write!(f, "I/O error: {e}"),
Self::TomlError(e) => write!(f, "TOML parsing error: {e}"), Self::Toml(e) => write!(f, "TOML parsing error: {e}"),
Self::ValidationError(s) => write!(f, "Configuration validation error: {s}"), Self::Validation(s) => write!(f, "Configuration validation error: {s}"),
} }
} }
} }