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 exception when the same module is in multiple repos #4264

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

HebaruSan
Copy link
Member

Problem

KSP-CKAN/NetKAN#10303 is throwing:

Unhandled Exception:
  System.ArgumentException: An item with the same key has already been added. Key: RSSOrigin-TopoRevampTextures16k v1.1.2
    at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x0015a] in <d636f104d58046fd9b195699bcb1a744>:0 
    at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <d636f104d58046fd9b195699bcb1a744>:0 
    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.List`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x0002d] in <69ada62907b24213a012734531df1db1>:0 
    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x00067] in <69ada62907b24213a012734531df1db1>:0 
    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector) [0x00000] in <69ada62907b24213a012734531df1db1>:0 
    at CKAN.ResolvedByNew..ctor (CKAN.CkanModule source, CKAN.RelationshipDescriptor relationship, CKAN.SelectionReason reason, System.Collections.Generic.IEnumerable`1[T] providers, System.Collections.Generic.ICollection`1[T] definitelyInstalling, System.Collections.Generic.ICollection`1[T] allInstalling, CKAN.IRegistryQuerier registry, System.Collections.Generic.ICollection`1[T] dlls, System.Collections.Generic.ICollection`1[T] installed, CKAN.Versioning.GameVersionCriteria crit, CKAN.OptionalRelationships optRels, System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue] relationshipCache) [0x0004d] in <dc3376c212ad46a191d66621f410eae2>:0 

Cause

This exception indicates that Registry.LatestAvailableWithProvides returned multiple copies of RSSOrigin-TopoRevampTextures16k, which would have happened because it's present in both the default repo and the custom repo that the validator uses for the freshly inflated replacement modules. It should only return the one with the higher repo priority.

Changes

  • Now the value type of the provides index is changed from HashSet to array to preserve the priority ordering of the source repos
  • Now Registry.LatestAvailableWithProvides calls Distinct to filter duplicates out of its returned list

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Registry Issues affecting the registry labels Nov 22, 2024
@HebaruSan HebaruSan merged commit 749fb70 into KSP-CKAN:master Nov 22, 2024
3 checks passed
@HebaruSan HebaruSan deleted the fix/exc-mod-in-mult-repos branch November 22, 2024 01:44
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 Registry Issues affecting the registry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant