KSP-CKAN / CKAN

The Comprehensive Kerbal Archive Network
https://forum.kerbalspaceprogram.com/index.php?/topic/197082-*
Other
1.99k stars 348 forks source link

Suppress exceptions for non-indexed mods #4170

Closed HebaruSan closed 3 months ago

HebaruSan commented 3 months ago

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:

https://github.com/KSP-CKAN/CKAN/blob/7ddc0ed4b1c71427db98e7e4a07e3d0a70ebd2e2/Core/Registry/Registry.cs#L717-L725

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

https://github.com/KSP-CKAN/CKAN/blob/2fc36b4706a8a0d0dd334a060988f6d9eacb52c0/Core/Registry/Registry.cs#L676-L683

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

https://github.com/KSP-CKAN/CKAN/blob/2fc36b4706a8a0d0dd334a060988f6d9eacb52c0/ConsoleUI/ModListScreen.cs#L55-L59

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

Changes

Fixes #4169.