diff --git a/ImperatorToCK3/CK3/Characters/CharacterCollection.cs b/ImperatorToCK3/CK3/Characters/CharacterCollection.cs index 358d4b7fb..2732846f0 100644 --- a/ImperatorToCK3/CK3/Characters/CharacterCollection.cs +++ b/ImperatorToCK3/CK3/Characters/CharacterCollection.cs @@ -46,8 +46,9 @@ Configuration config var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount - 1, }; - Parallel.ForEach(impWorld.Characters, parallelOptions, irCharacter => { - try { + + try { + Parallel.ForEach(impWorld.Characters, parallelOptions, irCharacter => { ImportImperatorCharacter( irCharacter, religionMapper, @@ -64,11 +65,15 @@ Configuration config config, unlocalizedImperatorNames ); - } catch (Exception e) { - Logger.Error($"Exception while importing Imperator character {irCharacter.Id}: {e}"); - Logger.Debug("Exception stack trace: " + e.StackTrace); - } - }); + }); + } catch (AggregateException e) { + var innerException = e.InnerExceptions[0]; + Logger.Error("Exception thrown during Imperator characters import: " + innerException.Message); + Logger.Debug("Exception stack trace: " + innerException.StackTrace); + + // Rethrow the inner exception to stop the program. + throw innerException; + } if (unlocalizedImperatorNames.Any()) { Logger.Warn("Found unlocalized Imperator names: " + string.Join(", ", unlocalizedImperatorNames)); diff --git a/ImperatorToCK3/CK3/Localization/CK3LocBlock.cs b/ImperatorToCK3/CK3/Localization/CK3LocBlock.cs index 3b140ff1e..093f917db 100644 --- a/ImperatorToCK3/CK3/Localization/CK3LocBlock.cs +++ b/ImperatorToCK3/CK3/Localization/CK3LocBlock.cs @@ -1,12 +1,13 @@ using commonItems.Collections; using commonItems.Localization; +using System.Collections.Concurrent; using System.Collections.Generic; namespace ImperatorToCK3.CK3.Localization; public class CK3LocBlock : IIdentifiable { // TODO: add ILocBlock interface that both this and commonItems' LocBlock would implement. private readonly string baseLanguage; - private readonly Dictionary localizations = new(); + private readonly ConcurrentDictionary localizations = new(); public string Id { get; } @@ -59,7 +60,7 @@ public string? this[string language] { } set { if (value is null) { - localizations.Remove(language); + localizations.Remove(language, out _); } else { localizations[language] = (value, CK3LocType.ConverterGenerated); } @@ -96,7 +97,7 @@ public void ModifyForEveryLanguage(CK3LocBlock otherBlock, TwoArgLocDelegate mod foreach (var language in localizations.Keys) { var locValue = modifyingFunction(localizations[language].Item1, otherBlock[language], language); if (locValue is null) { - localizations.Remove(language); + localizations.Remove(language, out _); continue; } localizations[language] = (locValue, CK3LocType.ConverterGenerated); @@ -112,7 +113,7 @@ public void ModifyForEveryLanguage(LocDelegate modifyingFunction) { foreach (var language in localizations.Keys) { var locValue = modifyingFunction(localizations[language].Item1, language); if (locValue is null) { - localizations.Remove(language); + localizations.Remove(language, out _); continue; } localizations[language] = (locValue, CK3LocType.ConverterGenerated);