-
Notifications
You must be signed in to change notification settings - Fork 3
fix: handle corrupted config files gracefully instead of crashing #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ public final class ConfigLoadContext { | |
| public final ModIncompatibilities incompats = new ModIncompatibilities(); | ||
| public final int version; | ||
| @Nullable public final Properties properties; | ||
| public boolean hasMissingOptions = false; | ||
|
|
||
| public ConfigLoadContext() { | ||
| if(Files.exists(FILE)) { | ||
|
|
@@ -32,10 +33,7 @@ private Properties loadProp() { | |
| return prop; | ||
| } | ||
| } catch(Exception e) { | ||
| // TODO: does passing Exception as object still log the stack trace? | ||
| LOGGER.error("Failed to load config from " + FILE + ". " + | ||
| "If you need to, you can delete the file to generate a new one.", e); | ||
| System.exit(1); | ||
| LOGGER.error("Failed to load config from " + FILE + ". Config will be regenerated with default values.", e); | ||
| return null; | ||
| } | ||
| } | ||
|
|
@@ -74,7 +72,8 @@ private String str(String name) { | |
|
|
||
| String str = properties.getProperty(name); | ||
| 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; | ||
| } | ||
|
Comment on lines
74
to
77
|
||
| return str; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name 'hasMissingOptions' suggests it only tracks missing config options, but conceptually it should also track malformed options that trigger regeneration. Consider renaming to 'needsRegeneration' or 'hasCorruptedOptions' to better reflect its purpose, or update the implementation to handle both missing and malformed values.