From a88ca4bb187c8abbd50ccf8c41c5e8bdcc11c868 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 23 Aug 2020 23:10:18 -0500 Subject: [PATCH] Improved error handling with new features --- IPA.Loader/Loader/Features/Feature.cs | 10 ++++++++-- IPA.Loader/Loader/PluginLoader.cs | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/IPA.Loader/Loader/Features/Feature.cs b/IPA.Loader/Loader/Features/Feature.cs index d51b94ea..b2c37052 100644 --- a/IPA.Loader/Loader/Features/Feature.cs +++ b/IPA.Loader/Loader/Features/Feature.cs @@ -106,6 +106,10 @@ namespace IPA.Loader.Features if (definingPlugin != declarer) return false; } + else + { + featureDelcarers.Add(name, definingPlugin); + } featureTypes.Add(name, type); return true; @@ -144,11 +148,13 @@ namespace IPA.Loader.Features // returns whether or not Initialize returned true, feature is always set when the thing exists public bool TryCreate(out Feature feature) { - feature = null; if (type == null) { if (!featureTypes.TryGetValue(Name, out type)) + { + feature = new EmptyFeature() { InvalidMessage = "No such feature type found", FeatureName = Name }; return false; + } } bool result; @@ -162,7 +168,7 @@ namespace IPA.Loader.Features catch (Exception e) { result = false; - feature = new EmptyFeature() { InvalidMessage = e.ToString() }; + feature = new EmptyFeature() { InvalidMessage = e.ToString(), FeatureName = Name }; } return result; } diff --git a/IPA.Loader/Loader/PluginLoader.cs b/IPA.Loader/Loader/PluginLoader.cs index b3b8facb..cbec90b8 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -878,11 +878,19 @@ namespace IPA.Loader var loaded = new HashSet(); foreach (var meta in PluginsMetadata) { - var exec = InitPlugin(meta, loaded); - if (exec != null) + try + { + var exec = InitPlugin(meta, loaded); + if (exec != null) + { + list.Add(exec); + loaded.Add(meta); + } + } + catch (Exception e) { - list.Add(exec); - loaded.Add(meta); + Logger.log.Critical($"Uncaught exception while loading pluign {meta.Name}:"); + Logger.log.Critical(e); } }