Summary
Implement comprehensive validation for configuration file values to prevent runtime errors from invalid settings. Add validation for timeout values, percentages, URLs, colors, enums, and other configuration parameters with helpful error messages.
Files to modify
src/theme/config/settings_ensure.rs (add validation functions)
src/theme/config/theme_loader.rs (add color format validation)
src/theme/config/keybinds_loader.rs (if exists, add keybind validation)
src/theme/types.rs (add validation methods to Settings struct)
Expected behavior
When invalid configuration values are detected:
- Show clear, actionable error messages explaining what's wrong
- Suggest valid alternatives or ranges where applicable
- Fall back to default values for individual invalid settings
- Allow the application to start with partially valid configuration
- Log warnings for invalid values that were corrected
Implementation approach
-
Add validation functions:
validate_layout_percentages() - ensure left/center/right sum to 100
validate_timeout_values() - check updates_refresh_interval is reasonable
validate_age_limits() - validate news age limits are positive
validate_mirror_count() - ensure mirror_count is reasonable
validate_color_formats() - verify hex/RGB color formats
validate_enum_values() - check sort_mode, package_marker are valid
validate_locale() - verify locale is supported or empty
-
Integrate validation:
- Call validation during config loading in
settings_ensure.rs
- Return detailed error messages with suggestions
- Fall back to defaults for invalid individual values
- Continue with valid configuration values
-
Error messaging:
- Include the invalid value and line number where possible
- Suggest valid alternatives (e.g., "use 30 instead of -5")
- Explain the constraint (e.g., "must be between 1-3600 seconds")
Testing
Additional context
Configuration values that need validation:
- Layout percentages:
layout_left_pct, layout_center_pct, layout_right_pct must sum to 100
- Timeouts:
updates_refresh_interval should be 1-3600 seconds
- Age limits:
news_max_age_days, startup_news_max_age_days should be positive or None
- Mirror count:
mirror_count should be 1-100
- Colors: All theme colors should be valid hex (#RRGGBB) or RGB (R,G,B) format
- Enums:
sort_mode, package_marker, installed_packages_mode should be valid variants
- Locale: Should be empty, "en-US", "de-DE", or "hu-HU"
- URLs: Any URL fields should be valid URLs (though none currently exist)
Follow existing error handling patterns in the codebase. Validation should be non-blocking - invalid individual values should fall back to defaults while preserving valid configuration.
Summary
Implement comprehensive validation for configuration file values to prevent runtime errors from invalid settings. Add validation for timeout values, percentages, URLs, colors, enums, and other configuration parameters with helpful error messages.
Files to modify
src/theme/config/settings_ensure.rs(add validation functions)src/theme/config/theme_loader.rs(add color format validation)src/theme/config/keybinds_loader.rs(if exists, add keybind validation)src/theme/types.rs(add validation methods to Settings struct)Expected behavior
When invalid configuration values are detected:
Implementation approach
Add validation functions:
validate_layout_percentages()- ensure left/center/right sum to 100validate_timeout_values()- check updates_refresh_interval is reasonablevalidate_age_limits()- validate news age limits are positivevalidate_mirror_count()- ensure mirror_count is reasonablevalidate_color_formats()- verify hex/RGB color formatsvalidate_enum_values()- check sort_mode, package_marker are validvalidate_locale()- verify locale is supported or emptyIntegrate validation:
settings_ensure.rsError messaging:
Testing
cargo checkpassescargo clippy --all-targets --all-features -- -D warningspassescargo test -- --test-threads=1passesAdditional context
Configuration values that need validation:
layout_left_pct,layout_center_pct,layout_right_pctmust sum to 100updates_refresh_intervalshould be 1-3600 secondsnews_max_age_days,startup_news_max_age_daysshould be positive or Nonemirror_countshould be 1-100sort_mode,package_marker,installed_packages_modeshould be valid variantsFollow existing error handling patterns in the codebase. Validation should be non-blocking - invalid individual values should fall back to defaults while preserving valid configuration.