From e12e7077042a68a5b3ffdb751513d6730337372f Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Mon, 19 Jul 2021 16:13:05 +0100 Subject: [PATCH] [PowerToys Run] Fix corrupt/outdated plugins load crash (#12424) * [PowerToys Run] Add type error catch and details * [PowerToys Run] don't load outdated config plugins Don't load plugins which don't have the new IcoPathDark and IcoPathLight fields. --- .../PowerLauncher/Plugin/PluginConfig.cs | 6 ++++++ src/modules/launcher/Wox.Plugin/PluginPair.cs | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/Plugin/PluginConfig.cs b/src/modules/launcher/PowerLauncher/Plugin/PluginConfig.cs index b9e98dbd34..02abd0710c 100644 --- a/src/modules/launcher/PowerLauncher/Plugin/PluginConfig.cs +++ b/src/modules/launcher/PowerLauncher/Plugin/PluginConfig.cs @@ -94,6 +94,12 @@ namespace PowerLauncher.Plugin return null; } + if (string.IsNullOrEmpty(metadata.IcoPathDark) || string.IsNullOrEmpty(metadata.IcoPathLight)) + { + Log.Error($"|PluginConfig.GetPluginMetadata|couldn't get icon information for config <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType); + return null; + } + if (!File.Exists(metadata.ExecuteFilePath)) { Log.Error($"|PluginConfig.GetPluginMetadata|execute file path didn't exist <{metadata.ExecuteFilePath}> for config <{configPath}", MethodBase.GetCurrentMethod().DeclaringType); diff --git a/src/modules/launcher/Wox.Plugin/PluginPair.cs b/src/modules/launcher/Wox.Plugin/PluginPair.cs index 7586bdead8..b97c5077ae 100644 --- a/src/modules/launcher/Wox.Plugin/PluginPair.cs +++ b/src/modules/launcher/Wox.Plugin/PluginPair.cs @@ -137,11 +137,21 @@ namespace Wox.Plugin catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { - Log.Exception($"Couldn't load assembly for {Metadata.Name}", e, MethodBase.GetCurrentMethod().DeclaringType); + Log.Exception($"Couldn't load assembly for {Metadata.Name} in {Metadata.ExecuteFilePath}", e, MethodBase.GetCurrentMethod().DeclaringType); + return false; + } + + Type[] types; + try + { + types = _assembly.GetTypes(); + } + catch (ReflectionTypeLoadException e) + { + Log.Exception($"Couldn't get assembly types for {Metadata.Name} in {Metadata.ExecuteFilePath}. The plugin might be corrupted. Uninstall PowerToys, manually delete the install folder and reinstall.", e, MethodBase.GetCurrentMethod().DeclaringType); return false; } - var types = _assembly.GetTypes(); Type type; try { @@ -149,7 +159,7 @@ namespace Wox.Plugin } catch (InvalidOperationException e) { - Log.Exception($"Can't find class implement IPlugin for <{Metadata.Name}>", e, MethodBase.GetCurrentMethod().DeclaringType); + Log.Exception($"Can't find class implement IPlugin for <{Metadata.Name}> in {Metadata.ExecuteFilePath}", e, MethodBase.GetCurrentMethod().DeclaringType); return false; } @@ -161,7 +171,7 @@ namespace Wox.Plugin catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { - Log.Exception($"Can't create instance for <{Metadata.Name}>", e, MethodBase.GetCurrentMethod().DeclaringType); + Log.Exception($"Can't create instance for <{Metadata.Name}> in {Metadata.ExecuteFilePath}", e, MethodBase.GetCurrentMethod().DeclaringType); return false; }