Better Enchanted Books (Fabric)

Better Enchanted Books (Fabric)

691k Downloads

[Bug] Launching the Kotlin Version Fails to Generated Config Files and Crashes

s4mothy opened this issue ยท 4 comments

commented

Describe the bug
The Kotlin version of the mod fails to generate the config files if they are not present, and will crash if they have not been generated previously (via the stable release version).

To Reproduce

  1. Download the Kotlin version of this mod and its dependencies to a fresh fabric-ready Minecraft (v.0.15.11)
  2. Launch the game.

Expected behavior
The game should launch without crashing. If the config files for the mod were not previously present, they should be generated in the config folder.

Screenshots
N/A

Crash Report
crash-2024-05-04_13.29.10-client.txt

Please include:

  • Minecraft Version: [1.20.1]
  • Mod Version [2.0.2]
  • CLOTH CONFIG [11.1.118], KOTLIN [1.10.19], FABRIC API [0.19.1]
commented

Yep, that makes sense.
Will push a fix later today :)

commented

Thanks for reaching out, unfortunately I cannot reproduce this issue.
Are there any more details about the instance or the multimc setup that you could provide?

Anyway I try it it's always safely creating a new config file if one wasn't there previously.

As it can be seen here the game shouldn't even crash if it fails to read?

try {
val jsonString = file.readText()
try {
// Try reading the data as the new format:
val data: SavedConfigs = SavedConfigs.readFromJson(jsonString)
enchantmentConfigurations.clear()
data.enchantments.forEach { enchantmentData ->
enchantmentConfigurations[enchantmentData.identifier] = enchantmentData
}
if (data.version >= 3) {
if (data.icons.isEmpty()) {
applicableItemIcons.addAll(DefaultConfigs.ICONS)
} else {
applicableItemIcons.addAll(data.icons)
}
}
} catch (e: SerializationException) {
LOGGER.warn("Failed to parse ${file.name}, going to try legacy parsing. This file will be overwritten when saved.")
try {
val old: Map<String, Map<String, Int>> = Json.decodeFromString(jsonString)
old.forEach { (key, value) ->
val identifier = Identifier.tryParse(key) ?: return@forEach
enchantmentConfigurations.clear()
enchantmentConfigurations[identifier] = EnchantmentData(
identifier = identifier,
priority = value["orderIndex"] ?: -1,
color = value["color"]?.let { Color(it) } ?: DefaultConfigs.getDefaultColor(identifier)
)
}
LOGGER.error("Legacy format read. Old index random values pointless. Suggest deleting settings file if no color values changed. File: ${file.absolutePath}")
} catch (e: SerializationException) {
LOGGER.warn("Failed to read from legacy format. Using default values.")
}
}
} catch (e: IOException) {
LOGGER.debug("No configuration file found. Creating new one.")
}

commented

It's not the reading but the writing that fails. save() doesn't create the bebook dir before trying to write the config file into it.

The Java version uses Files.createDirectories(CONFIG_DIR); for that.

P.S.
To reproduce the issue, simply delete the bebook dir.
If CONFIG_DIR is a File, you can also use CONFIG_DIR.mkdirs().

commented

The fix was released, just have to let it be approved by the platforms.