Fix NullReferenceException in csv/tsv export #3967
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 tonull
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 whenCkanModule.download
became aList
, the exporter was updated to use the first URL in that list, but that throws if the list is null.CKAN/Core/Exporters/DelimeterSeparatedValueExporter.cs
Line 68 in 457407e
Changes
[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?CkanModule.license
field is aList
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.