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

Suppress exceptions for non-indexed mods #4170

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

HebaruSan
Copy link
Member

Problem

ConsoleUI users who had installed CountryDoggosRandomKKBits see this exception as of KSP-CKAN/NetKAN#8711 and KSP-CKAN/CKAN-meta#3283:

Unhandled Exception:
CKAN.ModuleNotFoundKraken: Module not found: CountryDoggosRandomKKBits
  at CKAN.Registry.getAvail (System.String identifier) [0x00040] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.Registry.LatestCompatibleGameVersion (System.Collections.Generic.List`1[T] realVersions, System.String identifier) [0x0000d] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.ConsoleUI.ModListScreen+<>c__DisplayClass0_0.<.ctor>b__34 (CKAN.CkanModule m) [0x00016] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.ConsoleUI.Toolkit.ConsoleListBox`1[RowT].Draw (CKAN.ConsoleUI.Toolkit.ConsoleTheme theme, System.Boolean focused) [0x00259] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Draw (CKAN.ConsoleUI.Toolkit.ConsoleTheme theme) [0x0002e] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Interact (CKAN.ConsoleUI.Toolkit.ConsoleTheme theme) [0x0000f] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.ConsoleUI.Toolkit.ScreenContainer.Run (CKAN.ConsoleUI.Toolkit.ConsoleTheme theme, System.Action`1[T] process) [0x00021] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.ConsoleUI.ConsoleCKAN..ctor (CKAN.GameInstanceManager mgr, System.String themeName, System.Boolean debug) [0x000b1] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.ConsoleUI.ConsoleUI.Main_ (CKAN.GameInstanceManager manager, System.String themeName, System.Boolean debug) [0x00005] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.CmdLine.MainClass.ConsoleUi (CKAN.GameInstanceManager manager, CKAN.CmdLine.ConsoleUIOptions opts) [0x00033] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.CmdLine.MainClass.RunSimpleAction (CKAN.CmdLine.Options cmdline, CKAN.CmdLine.CommonOptions options, System.String[] args, CKAN.IUser user, CKAN.GameInstanceManager manager) [0x002ea] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.CmdLine.MainClass.Execute (CKAN.GameInstanceManager manager, CKAN.CmdLine.CommonOptions opts, System.String[] args) [0x002b4] in <5619c0490fe14ea1b83e6c508f8301de>:0
  at CKAN.CmdLine.MainClass.Main (System.String[] args) [0x000e9] in <5619c0490fe14ea1b83e6c508f8301de>:0

Cause

In #3904, Registry.LatestCompatibleGameVersion was changed from never throwing exceptions:

/// <summary>
/// Return the latest game version compatible with the given mod.
/// </summary>
/// <param name="identifier">Name of mod to check</param>
public GameVersion LatestCompatibleGameVersion(List<GameVersion> realVersions,
string identifier)
=> available_modules.TryGetValue(identifier, out AvailableModule availMod)
? availMod.LatestCompatibleGameVersion(realVersions)
: null;

To possibly throwing ModuleNotFoundKraken via getAvail if the identifier wasn't indexed:

/// <summary>
/// Return the latest game version compatible with the given mod.
/// </summary>
/// <param name="identifier">Name of mod to check</param>
public GameVersion LatestCompatibleGameVersion(List<GameVersion> realVersions,
string identifier)
=> getAvail(identifier).Select(am => am.LatestCompatibleGameVersion(realVersions))
.Max();

ConsoleUI uses that function as if its failure mode is to return null, not throw an exception:

}, new ConsoleListBoxColumn<CkanModule>() {
Header = Properties.Resources.ModListMaxGameVersionHeader,
Width = 20,
Renderer = m => registry.LatestCompatibleGameVersion(game.KnownVersions, m.identifier)?.ToString() ?? "",
Comparer = (a, b) => registry.LatestCompatibleGameVersion(game.KnownVersions, a.identifier).CompareTo(registry.LatestCompatibleGameVersion(game.KnownVersions, b.identifier))

CountryDoggosRandomKKBits is no longer indexed, so now that exception is being thrown and not caught.

Changes

  • Now Registry.LatestCompatibleGameVersion doesn't throw ModuleNotFoundKraken anymore, as it was originally
  • Now the value of Registry.ProvidedByInstalled is cached while the installed mods remain the same to slightly improve performance, as suggested by a TODO comment long ago

Fixes #4169.

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN labels Aug 22, 2024
@HebaruSan HebaruSan merged commit 9ce588f into KSP-CKAN:master Aug 22, 2024
3 checks passed
@HebaruSan HebaruSan deleted the fix/consoleui-darkkan-crash branch August 22, 2024 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: CountryDoggosRandomKKBits-related Crash
1 participant