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 NullReferenceException in csv/tsv export #3967

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

HebaruSan
Copy link
Member

Problem

If you have a KSP1 DLC installed and you try to export your installed mod list in .csv or .tsv format, this exception is thrown:

System.NullReferenceException: Object reference not set to an instance of an object.
   at CKAN.Exporters.DelimeterSeparatedValueExporter.Export(IRegistryQuerier registry, Stream stream)
   at CKAN.GUI.Main.exportModListToolStripMenuItem_Click(Object sender, EventArgs e)

Reported by forum user orionguy:

https://forum.kerbalspaceprogram.com/topic/197082-ckan-the-comprehensive-kerbal-archive-network-v1332-laplace-ksp-2-support/?do=findComment&comment=4348938

Cause

DLCs have CkanModule.download set to null because we can't install them for you. Prior to #3877, this would have resulted in an empty string being saved to the file, but when CkanModule.download became a List, the exporter was updated to use the first URL in that list, but that throws if the list is null.

WriteUri(mod.Module.download[0]),

Changes

  • Now [0] is changed to the null-conditional index access operator ?[0], which will return null when the property is null instead of throwing an exception. This allows the export to complete. Don't you just love null references and exceptions both?
  • The CkanModule.license field is a List as well, but it was being exported as if it was a string, which put some type signature junk in the output file. Now we concatenate the licenses with a ; delimiter, so that looks better now too.

@HebaruSan HebaruSan added the Bug label Dec 20, 2023
@HebaruSan HebaruSan added Easy This is easy to fix Core (ckan.dll) Issues affecting the core part of CKAN labels Dec 20, 2023
@HebaruSan HebaruSan merged commit 224dab8 into KSP-CKAN:master Dec 20, 2023
8 checks passed
@HebaruSan HebaruSan deleted the fix/delimiter-export-nre branch December 20, 2023 03:17
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 Easy This is easy to fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant