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 config file corruption handling by implementing graceful recovery instead of crashing the application. When a config file is corrupted or has missing/malformed options, the system now logs warnings and regenerates the config with default values.

Key changes:

  • Removes System.exit(1) call when config loading fails, allowing recovery
  • Adds hasMissingOptions flag to track when options are missing and trigger regeneration
  • Adds TRUNCATE_EXISTING flag to prevent leftover data from corrupting regenerated configs

Reviewed changes

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

File Description
ConfigLoadContext.java Removes fatal error handling, adds tracking for missing options, and returns null to allow fallback to defaults
Config.java Adds condition to regenerate config when options are missing, includes TRUNCATE_EXISTING to ensure clean config writes

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

Comment on lines 74 to 77
if(str == null) {
throw new IllegalStateException("Config option " + name + " not found");
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.

The boolOrDefault and intOrDefault methods still throw IllegalStateException for malformed values (e.g., invalid boolean strings or non-numeric values). This is inconsistent with the PR's goal of handling corrupted configs gracefully. When these exceptions are thrown, they will propagate up and potentially crash the application during static initialization. Consider catching these exceptions and setting hasMissingOptions to true, or returning the default value and logging a warning instead.

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