Skip to content

Conversation

@neilhuang007
Copy link

  • Use default values when config options are missing instead of throwing
  • Regenerate config automatically when options are missing or malformed
  • Add TRUNCATE_EXISTING to prevent leftover data from corrupting config
  • Remove System.exit(1) on config parse errors to allow recovery

Fixes #115

- Use default values when config options are missing instead of throwing
- Regenerate config automatically when options are missing or malformed
- Add TRUNCATE_EXISTING to prevent leftover data from corrupting config
- Remove System.exit(1) on config parse errors to allow recovery

Fixes imthosea#115
Copilot AI review requested due to automatic review settings December 25, 2025 00:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the robustness of config file handling by gracefully recovering from corrupted or incomplete configuration files instead of crashing the application. The changes allow the application to continue running with default values when config issues are detected, and automatically regenerate the config file.

Key changes:

  • Removed System.exit(1) calls when config parsing fails, allowing recovery instead of crashing
  • Added tracking for missing config options via hasMissingOptions flag to trigger automatic regeneration
  • Added TRUNCATE_EXISTING flag to file writing to prevent partial data corruption

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
common/src/main/java/me/thosea/badoptimizations/config/ConfigLoadContext.java Added hasMissingOptions flag, removed System.exit(1) on config load failure, changed missing option handling from throwing exceptions to logging warnings and using defaults
common/src/main/java/me/thosea/badoptimizations/config/Config.java Added hasMissingOptions check to config regeneration condition, added TRUNCATE_EXISTING to prevent leftover data corruption

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to 77
LOGGER.warn("Config option {} not found - using default value. Config will be regenerated.", name);
hasMissingOptions = true;
}
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When str() returns null due to a missing config option, hasMissingOptions is set to true. However, if a config value is malformed (e.g., a boolean option has an invalid value, or an integer option is not a valid number or is negative), the code in boolOrDefault() and intOrDefault() throws IllegalStateException without setting hasMissingOptions = true. This means malformed values won't trigger automatic config regeneration as described in the PR. Consider catching these exceptions and setting hasMissingOptions = true to ensure malformed values also trigger regeneration.

Copilot uses AI. Check for mistakes.
@imthosea imthosea closed this Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants