From df0a4e62f5adf4f32110f49d2c449b402ae8755f Mon Sep 17 00:00:00 2001 From: MapleWheels Date: Tue, 7 Apr 2026 15:43:01 -0400 Subject: [PATCH] Added logging for additional plugin loading exceptions. --- .../_Services/PluginManagementService.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs index 6c23761dd..b3b99ad09 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs @@ -364,18 +364,35 @@ public class PluginManagementService : IAssemblyManagementService .Where(al => executionOrder.Contains(al.Key)) .Where(al => !excludeAlreadyRunningPackages || !_pluginInstances.ContainsKey(al.Key)) .SelectMany(al => al.Value.Assemblies.Select(ass => (al.Key, ass))) - .SelectMany(kvp => kvp.ass.GetSafeTypes() - .Where(type => - type is { IsInterface: false, IsAbstract: false, IsGenericType: false } - && type.IsAssignableTo(typeof(IAssemblyPlugin))) - .Select(type => (kvp.Key, type))) + .SelectMany<(ContentPackage Key, Assembly ass), (ContentPackage Key, Type type)>(kvp => + { + try + { + return kvp.ass.GetTypes() + .Where(type => + type is { IsInterface: false, IsAbstract: false, IsGenericType: false } + && type.IsAssignableTo(typeof(IAssemblyPlugin))) + .Select(type => (kvp.Key, type)); + } + catch (ReflectionTypeLoadException re) + { + results.WithError(new Error($"Failed to get types from Package '{kvp.Key.Name}'")); + results.WithError(new ExceptionalError(re)); + } + catch (Exception e) + { + results.WithError(new Error($"Failed to get types from Package '{kvp.Key.Name}'")); + results.WithError(new ExceptionalError(e)); + } + return new List<(ContentPackage Key, Type type)>(); + }) .GroupBy(kvp => kvp.Key, kvp => kvp.type) .OrderBy(exeGrp => executionOrder.IndexOf(exeGrp.Key)) .ToImmutableArray(); if (toLoad.Length == 0) { - return FluentResults.Result.Ok(); + return results; } _logger.LogMessage($"Activating {nameof(IAssemblyPlugin)} instances"); @@ -400,7 +417,7 @@ public class PluginManagementService : IAssemblyManagementService } catch (Exception e) { - results.WithError(new ExceptionalError(e)); + results.WithError(new ExceptionalError($"Failed to instantiate mod: {packageTypes.Key.Name}", e)); continue; } }