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

Nullable references, net8.0, blend registry alert dot, netkan fixes #4171

Merged
merged 11 commits into from
Sep 3, 2024

Conversation

HebaruSan
Copy link
Member

Motivation

References in C#'s default type system can be either an object or null, and if you try to use a null reference as if it was an object, a null reference exception is thrown, which can wreck things for end users. The only way to avoid this is to track in your brain whether every reference can be null, which generally requires checking for null frequently, which is tedious and easy to forget.

C# 8 added the ability to make references non-nullable by default. This means that a variable or function's type can indicate that parameters and return values can't be null, and the compiler can enforce it. References can be made nullable by appending ? to the type, just like for the already existing nullable types, and the compiler will check the code and emit warnings if such references are used in a way that could cause null reference exceptions.

https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references

This feature provides the tools to eliminate null reference exceptions via compile-time checks, which is a tremendous step forward.

Changes

  • All projects have had the following changes made:
    • C# language version is updated from 7.3 to 9 (which has some additional features that make nullable references more workable)
    • Nullable references are enabled and all code is updated to use them properly
    • Warnings are now treated as errors (except for a few specific ones that we want to be raised but don't want to fix)
    • The net7.0 target framework is replaced by net8.0 (which is as far as we can go unless and until we migrate away from Newtonsoft.Json)
  • The new indexes and ranges feature is used to replace substring operations

Additional fixes and small features

While working on the above, a few other problems and ideas came up.

  • @linuxgurugamer recently replaced 9 mods twice in rapid sequence, and half of them didn't have their hashes update properly in the metadata (I made a spreadsheet to track the details). This was probably because of some combination of timezones being set wrong somewhere and SpaceDock's traffic server caching downloads. But later, when the 30-day cache purge job from the Infra ran, only the download_size property was updated, not the hashes! This is very strange and suggests the hashes are being cached when they shouldn't be.
    Now when we detect that a ZIP file is deleted from the cache, we also purge its hashes from both the in-memory and on-disk caches. Hopefully this will make the hashes update properly after a cache purge.
  • The KSP2 mods have spurious missing-dependency inflation warnings currently because the SpaceWarpInfo validation check was embedded in the SpaceWarpInfo translator and I eliminated most of the duplicated metadata for multi-hosted KSP2 netkans in Remove spec version and license, deduplicate fields KSP2-NetKAN#181.
    Now this validator is separate and runs at the end after the multi-hosting merge step, so these warnings will go away.
  • The alert dot from Visually indicate to users that they should click Refresh #4133 only had two colors; now it blends from yellow to red gradually day by day

@HebaruSan HebaruSan added Bug Something is not working as intended Enhancement New features or functionality GUI Issues affecting the interactive GUI Cmdline Issues affecting the command line Core (ckan.dll) Issues affecting the core part of CKAN Netkan Issues affecting the netkan data AutoUpdate Issues affecting the automatic updating Tests Issues affecting the internal tests ConsoleUI Issues affecting the interactive console UI labels Sep 3, 2024
@HebaruSan HebaruSan merged commit 49fe676 into KSP-CKAN:master Sep 3, 2024
3 checks passed
@HebaruSan HebaruSan deleted the feature/nullable-refs branch September 3, 2024 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoUpdate Issues affecting the automatic updating Bug Something is not working as intended Cmdline Issues affecting the command line ConsoleUI Issues affecting the interactive console UI Core (ckan.dll) Issues affecting the core part of CKAN Enhancement New features or functionality GUI Issues affecting the interactive GUI Netkan Issues affecting the netkan data Tests Issues affecting the internal tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant