KosmosPrime / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
25 stars 16 forks source link

Config error occurred when running the client a second time. #7

Closed inraito closed 10 months ago

inraito commented 10 months ago

Every time I try to run the client for a second time, it just crashes with instructions to delete the config file in the path:config/opencomputers/settings.conf to restore a default behaviour. And it worked perfectly fine if i do so, which is also true when I boot the client for the first time(because that config file haven't been generated yet i believe).

Then by using debugger, I found that the error directly resulted from some code related to the config file's cross-version compatibility. To put it simply, it seems that though it should be a 1.8.3(maybe -snapshot?) config, it was marked as 1.8.0-snapshot, and crashed my client.

I've read the code and I think that 1.8.0-snapshot was from the mod_version field in gradle.properties file. And it works well if i change that to 1.8.3-snapshot. Also I found there's a mod.version in build.properties file, and both of the fields seem to be used in buildscript. And that's all. I'm not sure if this happened because of my environment.

By the way, I'm using Intellij IDEA and on WIndows, and i basically use the task in IDEA instead of the runClient task on gradle. Although the same issue happened too if I run the gradle runClient task.

inraito commented 10 months ago

Sorry, not changing to 1.8.3-snapshot, it has to be 1.8.3. Because there's an if statement ask if [?, 1.8.3) contains current version. 1.8.3 avoid that while 1.8.3-snapshot don't. I thought i was using 1.8.3-snapshot, but it turned out that it actually was 1.8.3.

KosmosPrime commented 10 months ago

I'm not seeing a crash when upgrading a 1.8.0-snapshot (or 1.8.3-snapshot) config to a 1.8.3 mod, at least in production (local gradle dev env decided that functioning properly is no fun yet again). Which config version & mod version are causing the issue exactly? Alternatively, given that you've stepped in with a debugger, do you remember what caused the underlying exception (the cause of the exception which is asking you to delete your configs)?

inraito commented 10 months ago

Yes, I've checked the 1.8.3 release too, it worked pretty well. The thing is, in production, it generates settings.conf correctly(with the basically last line saying: version="1.8.3") while in my dev env, it just generates wrongly(with the last line saying: version="1.8.0-snapshot").

I'm quite sure the crash was from li.cil.oc.Settings.scala:634 where it checks if the config is generated by former versions. If so, it uses different protocol to parse the config file. Then, as far as i understand it, in my dev, the config file is generated under the 1.8.3 prototol but declaring that it is a 1.8.0-snapshot, which leads to the parser using the wrong protocol and finally some keys are missing, and boom. The exact exception thrown is not quite useful I think, it seemed to assume that it is my reckless modification that caused this problem but actually I've done nothing.

I don't quite get what you mean by "which config version & mod version". I'm using the latest commit on dev-MC1.16(with no modification), so the mod version should be 1.8.3 I assume, and the config file is generate by itself, so it should also be 1.8.3, shouldn't it.

KosmosPrime commented 10 months ago

The exact exception thrown is not quite useful I think, it seemed to assume that it is my reckless modification that caused this problem but actually I've done nothing.

If the crash wrongly assumes that it's your fault, especially when crashing while patching, it's a bug in the code. That's why I need the exact error, to be able to fix that bug.

I don't quite get what you mean by "which config version & mod version". I'm using the latest commit on dev-MC1.16(with no modification), so the mod version should be 1.8.3 I assume, and the config file is generate by itself, so it should also be 1.8.3, shouldn't it.

For reasons relating to how the build script has been set up, the dev-MC1.16 branch actually builds a 1.8.0-snapshot version by default. I've tried adjusting the version of the 1.8.3 release to generate a snapshot config but couldn't replicate the issue, I need to know what's in the config file to be able to reproduce the error.

inraito commented 10 months ago

Errrrr, in my dev env, I don't have to do anything to reproduce it, just checkout the latest commit, and run the runClient twice(without any modifications). I'm not sure if it is related to my dev env.

And the exception was thrown on li.cil.oc.Settings.scala:553 caused by RuntimeException:"No configuration setting found for key 'opencomputers.internet.whitelist'".

catch 
{
        case e: Throwable =>
        if (file.exists()) {
            throw new RuntimeException("Error parsing configuration file. To restore defaults, delete '" + file.getName + "' and restart the game.", e)//553
        }
        settings = new Settings(defaults.getConfig("opencomputers"))
        defaults
}
KosmosPrime commented 10 months ago

As far as I understand, this issue happens because the default config has a wrong version, so that, on next launch, OC tries to upgrade it and crashes because the version is 1.8.0-snapshot and assumes the old internet config options are present (which they are not). The problem is that the default config version is sourced from application.conf which replaced during the processResources step to be ${mod_version}, while the mod version (which this is compared to) is in META-INF/mods.toml which is replaced during the same step to also be ${mod_version}. The only way I can see for this issue to arise is if the mod_version variable thus changes between builds, which you say you didn't (without any modifications) and leads to me not seeing any such crash. TL;DR: I hope this fixes it (you'll still have to clear old configs once) but if not then I'm closing this issue because I'm unable to reproduce.