diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 182cfb6b1..dc1ff8da1 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -68,7 +69,14 @@ namespace Dalamud if (!configuration.IsResumeGameAfterPluginLoad) { NativeFunctions.SetEvent(mainThreadContinueEvent); - _ = ServiceManager.InitializeEarlyLoadableServices(); + try + { + _ = ServiceManager.InitializeEarlyLoadableServices(); + } + catch (Exception e) + { + Log.Error(e, "Service initialization failure"); + } } else { @@ -83,20 +91,13 @@ namespace Dalamud }; await Task.WhenAny(tasks); - foreach (var task in tasks) - { - if (task.IsFaulted) - throw task.Exception!; - } + var faultedTasks = tasks.Where(x => x.IsFaulted).Select(x => (Exception)x.Exception!).ToArray(); + if (faultedTasks.Any()) + throw new AggregateException(faultedTasks); NativeFunctions.SetEvent(mainThreadContinueEvent); await Task.WhenAll(tasks); - foreach (var task in tasks) - { - if (task.IsFaulted) - throw task.Exception!; - } } catch (Exception e) { diff --git a/Dalamud/ServiceManager.cs b/Dalamud/ServiceManager.cs index 00ee3790e..5dc6d08f1 100644 --- a/Dalamud/ServiceManager.cs +++ b/Dalamud/ServiceManager.cs @@ -114,9 +114,9 @@ namespace Dalamud { try { - using var blockingServiceInitializeTimings = Timings.Start("BlockingServices Init"); await Task.WhenAll(blockingEarlyLoadingServices.Select(x => getAsyncTaskMap[x])); BlockingServicesLoadedTaskCompletionSource.SetResult(); + Timings.Event("BlockingServices Initialized"); } catch (Exception e) { diff --git a/Dalamud/Service{T}.cs b/Dalamud/Service{T}.cs index 7079fe17f..e8fd0f32f 100644 --- a/Dalamud/Service{T}.cs +++ b/Dalamud/Service{T}.cs @@ -52,16 +52,14 @@ namespace Dalamud try { var x = await ConstructObject(); - if (attr?.IsAssignableTo(typeof(ServiceManager.BlockingEarlyLoadedService)) == true) - ServiceManager.Log.Debug("Service<{0}>: Construction complete", typeof(T).Name); + ServiceManager.Log.Debug("Service<{0}>: Construction complete", typeof(T).Name); InstanceTcs.SetResult(x); return x; } catch (Exception e) { + ServiceManager.Log.Error(e, "Service<{0}>: Construction failure", typeof(T).Name); InstanceTcs.SetException(e); - if (attr?.IsAssignableTo(typeof(ServiceManager.BlockingEarlyLoadedService)) == true) - ServiceManager.Log.Error(e, "Service<{0}>: Construction failure", typeof(T).Name); throw; } }));