Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void init() {}
// config v5 adds caching hooks and changes debug hud comment
// config v6 only changes comments

if(!ctx.fromExistingFile() || ver < CURRENT_CONFIG_VER) {
if(!ctx.fromExistingFile() || ver < CURRENT_CONFIG_VER || ctx.hasMissingOptions) {
try {
writeConfig();
} catch(Exception e) {
Expand Down Expand Up @@ -126,6 +126,6 @@ public static void writeConfig() throws Exception {
CURRENT_CONFIG_VER
);

Files.writeString(FILE, data, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
Files.writeString(FILE, data, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 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.

Copilot uses AI. Check for mistakes.

public ConfigLoadContext() {
if(Files.exists(FILE)) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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
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 handles missing config options gracefully, it doesn't address the complete issue described in #115. The config corruption in the issue shows malformed values (incomplete strings like "enable_sky_color_cach" instead of "enable_sky_color_caching"). When such malformed values are parsed by boolOrDefault or intOrDefault, they will still throw IllegalStateException and crash. Consider also setting hasMissingOptions = true in those parsing methods when they encounter malformed values, rather than throwing exceptions.

Copilot uses AI. Check for mistakes.
return str;
}
Expand Down