Skip to content
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

Fix loading of legacy registry.json files #3937

Merged
merged 1 commit into from Dec 5, 2023

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Dec 5, 2023

Problem

If you install some mods with the current release of CKAN and then switch to the current dev build, it will show no mods installed.

Thanks to @JonnyOThan for reporting this on Discord.

Cause

In #3904, we retired Registry.available_modules and Registry.download_counts. However, since the old client will crash if these are absent or null, we created a JsonAlwaysEmptyObjectConverter to ensure they're always saved as an empty JSON object ({}). This converter's deserialization function worked by simply creating an empty copy of the required type (Dictionary<string, string> in this case).

However, a JsonConverter's ReadJson implementation must call JToken.Load(reader) to extract the current token from the input stream! We weren't doing that, and the parse was stopping right after that point, before Registry.installed_modules was deserialized. Maybe Newtonsoft.Json considers that an error condition?

This doesn't happen with a "new" registry because it doesn't call the converter when the JSON object is already empty (I think).

Changes

Now JsonAlwaysEmptyObjectConverter.ReadJson calls JToken.Load(reader) and ignores its return value before it returns the empty dictionary, which allows the full Registry object to finish deserializing.

I'll probably self-review this because it's small and a regression.

@HebaruSan HebaruSan added Bug Core (ckan.dll) Issues affecting the core part of CKAN Registry Issues affecting the registry labels Dec 5, 2023
@HebaruSan HebaruSan merged commit 5c77a68 into KSP-CKAN:master Dec 5, 2023
8 checks passed
@HebaruSan HebaruSan deleted the fix/registry-load branch December 5, 2023 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Core (ckan.dll) Issues affecting the core part of CKAN Registry Issues affecting the registry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant