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 fixes crashes caused by corrupted config files by implementing graceful recovery with default values. When config options are missing or the config file cannot be parsed, the mod will now use default values and automatically regenerate the config file instead of crashing with IllegalStateException.

Key changes:

  • Replace crash-on-parse-error behavior with graceful recovery using default values
  • Automatically regenerate config when options are missing or file is corrupted
  • Add TRUNCATE_EXISTING flag to prevent file corruption from leftover data

Reviewed changes

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

File Description
ConfigLoadContext.java Removes System.exit(1) call on config load failure, adds hasMissingOptions flag to track missing config options, and changes missing option handling from throwing exceptions to logging warnings and using defaults
Config.java Adds hasMissingOptions check to config regeneration condition and adds TRUNCATE_EXISTING flag to prevent incomplete writes from leaving corrupted leftover data

💡 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.

While this change handles missing options correctly, it doesn't address malformed option values (e.g., "tru" instead of "true" or "enabl" as shown in issue #115). When a config option exists but has a malformed value, boolOrDefault and intOrDefault will still throw IllegalStateException, causing the same crash this PR aims to fix. Consider also catching these exceptions and setting hasMissingOptions=true to trigger config regeneration, or return the default value after logging a warning.

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