From 0b250161bece350074366488c5b1e0effabc848c Mon Sep 17 00:00:00 2001 From: Archangel Date: Tue, 5 Aug 2025 03:51:18 +0200 Subject: [PATCH] If profile can't be loaded log the exception and throw --- .../Services/ProfileMigratorService.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs b/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs index 9954a34b..e174d27e 100644 --- a/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs @@ -37,7 +37,7 @@ public class ProfileMigratorService( ) { return profile.Deserialize(JsonUtil.JsonSerializerOptionsNoIndent) - ?? throw new InvalidOperationException($"Could not deserialize the profile {profileId}"); + ?? throw new InvalidOperationException($"Could not deserialize the profile: {profileId}"); } var ranMigrations = new List(); @@ -59,9 +59,27 @@ public class ProfileMigratorService( } } - var sptReadyProfile = - profile.Deserialize(JsonUtil.JsonSerializerOptionsNoIndent) - ?? throw new InvalidOperationException($"Could not deserialize the profile {profileId}"); + SptProfile sptReadyProfile; + + try + { + sptReadyProfile = + profile.Deserialize(JsonUtil.JsonSerializerOptionsNoIndent) + ?? throw new InvalidOperationException($"Could not deserialize the profile."); + } + catch (Exception ex) + { + logger.Critical($"Could not load profile: {profileId}"); + logger.Critical(ex.ToString()); + + if (ex.StackTrace is not null) + { + logger.Critical(ex.StackTrace); + } + + // Throw here, immediately stops execution of the server upon detecting a messed up profile + throw; + } foreach (var ranMigration in ranMigrations) {