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;

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 +75 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.

The exceptions thrown in boolOrDefault (line 50) and intOrDefault (lines 62, 65) when config values are malformed are not handled. These exceptions will prevent the graceful recovery that this PR aims to provide. When a config value is malformed (e.g., "maybe" instead of "true"/"false", or "abc" instead of a number), the application will still crash instead of using the default value.

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