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:
parent
63cab6e631
commit
fe93a50f9e
3 changed files with 15 additions and 15 deletions
|
@ -74,7 +74,7 @@ pub fn set_battery_charge_thresholds(start_threshold: u8, stop_threshold: u8) ->
|
|||
// Validate thresholds using `BatteryChargeThresholds`
|
||||
let thresholds =
|
||||
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(format!("Invalid battery threshold values: {e}")),
|
||||
|
|
|
@ -26,7 +26,7 @@ pub fn load_config_from_path(specific_path: Option<&str>) -> Result<AppConfig, C
|
|||
if path.exists() {
|
||||
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,
|
||||
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
|
||||
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 =
|
||||
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
|
||||
let mut charger_profile = toml_app_config.charger.clone();
|
||||
|
|
|
@ -23,17 +23,17 @@ pub struct BatteryChargeThresholds {
|
|||
impl BatteryChargeThresholds {
|
||||
pub fn new(start: u8, stop: u8) -> Result<Self, ConfigError> {
|
||||
if stop == 0 {
|
||||
return Err(ConfigError::ValidationError(
|
||||
return Err(ConfigError::Validation(
|
||||
"Stop threshold must be greater than 0%".to_string(),
|
||||
));
|
||||
}
|
||||
if start >= stop {
|
||||
return Err(ConfigError::ValidationError(format!(
|
||||
return Err(ConfigError::Validation(format!(
|
||||
"Start threshold ({start}) must be less than stop threshold ({stop})"
|
||||
)));
|
||||
}
|
||||
if stop > 100 {
|
||||
return Err(ConfigError::ValidationError(format!(
|
||||
return Err(ConfigError::Validation(format!(
|
||||
"Stop threshold ({stop}) cannot exceed 100%"
|
||||
)));
|
||||
}
|
||||
|
@ -100,29 +100,29 @@ pub struct AppConfig {
|
|||
// Error type for config loading
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
IoError(std::io::Error),
|
||||
TomlError(toml::de::Error),
|
||||
ValidationError(String),
|
||||
Io(std::io::Error),
|
||||
Toml(toml::de::Error),
|
||||
Validation(String),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ConfigError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self::IoError(err)
|
||||
Self::Io(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<toml::de::Error> for ConfigError {
|
||||
fn from(err: toml::de::Error) -> Self {
|
||||
Self::TomlError(err)
|
||||
Self::Toml(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ConfigError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::IoError(e) => write!(f, "I/O error: {e}"),
|
||||
Self::TomlError(e) => write!(f, "TOML parsing error: {e}"),
|
||||
Self::ValidationError(s) => write!(f, "Configuration validation error: {s}"),
|
||||
Self::Io(e) => write!(f, "I/O error: {e}"),
|
||||
Self::Toml(e) => write!(f, "TOML parsing error: {e}"),
|
||||
Self::Validation(s) => write!(f, "Configuration validation error: {s}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue