[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.
This commit is contained in:
Jaime Bernardo
2021-07-19 16:13:05 +01:00
committed by GitHub
parent f4a54b667e
commit e12e707704
2 changed files with 20 additions and 4 deletions

View File

@@ -94,6 +94,12 @@ namespace PowerLauncher.Plugin
return null; 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)) if (!File.Exists(metadata.ExecuteFilePath))
{ {
Log.Error($"|PluginConfig.GetPluginMetadata|execute file path didn't exist <{metadata.ExecuteFilePath}> for config <{configPath}", MethodBase.GetCurrentMethod().DeclaringType); Log.Error($"|PluginConfig.GetPluginMetadata|execute file path didn't exist <{metadata.ExecuteFilePath}> for config <{configPath}", MethodBase.GetCurrentMethod().DeclaringType);

View File

@@ -137,11 +137,21 @@ namespace Wox.Plugin
catch (Exception e) catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types #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; return false;
} }
var types = _assembly.GetTypes();
Type type; Type type;
try try
{ {
@@ -149,7 +159,7 @@ namespace Wox.Plugin
} }
catch (InvalidOperationException e) 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; return false;
} }
@@ -161,7 +171,7 @@ namespace Wox.Plugin
catch (Exception e) catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types #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; return false;
} }