Pathoschild / SMAPI

The modding API for Stardew Valley.
https://smapi.io/
GNU Lesser General Public License v3.0
1.82k stars 259 forks source link

Improve error when a mod adds duplicate translations #448

Closed Pathoschild closed 6 years ago

Pathoschild commented 6 years ago

When a mod has duplicate translations, an ArgumentException is thrown which doesn't provide any info about which mod failed:

[21:21:33 ERROR SMAPI] A mod failed handling the GameEvents.InitializeInternal event: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary2..ctor(IDictionary2 dictionary, IEqualityComparer1 comparer) at StardewModdingAPI.Framework.ModHelpers.TranslationHelper.SetTranslations(IDictionary2 translations) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\ModHelpers\TranslationHelper.cs:line 81 at StardewModdingAPI.Program.ReloadTranslations(IEnumerable1 mods) in C:\source_Stardew\SMAPI\src\SMAPI\Program.cs:line 998 at StardewModdingAPI.Program.LoadMods(IModMetadata[] mods, JsonHelper jsonHelper, SContentManager contentManager) in C:\source_Stardew\SMAPI\src\SMAPI\Program.cs:line 847 at StardewModdingAPI.Program.InitialiseAfterGameStart() in C:\source_Stardew\SMAPI\src\SMAPI\Program.cs:line 373 at StardewModdingAPI.Program.b__18_5(Object sender, EventArgs e) in C:\source_Stardew\SMAPI\src\SMAPI\Program.cs:line 201 at StardewModdingAPI.Framework.InternalExtensions.SafelyRaisePlainEvent(IMonitor monitor, String name, IEnumerable`1 handlers, Object sender, EventArgs args) in C:\source_Stardew\SMAPI\src\SMAPI\Framework\InternalExtensions.cs:line 41 [21:21:33 TRACE SMAPI] Context: locale set to en.

Show a more friendly and informative error.

Pathoschild commented 6 years ago

Done in develop for the upcoming SMAPI 2.5, which will print a warning to the console instead:

[Affected Mod Name] Mod's i18n/de.json has duplicate translation keys: [default-name.CHEST]. Keys are case-insensitive.