Skip to content

Commit

Permalink
[PowerToys Run] Fix corrupt/outdated plugins load crash (#12424)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
jaimecbernardo committed Jul 19, 2021
1 parent f4a54b6 commit e12e707
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/modules/launcher/PowerLauncher/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ private static PluginMetadata GetPluginMetadata(string pluginDirectory)
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);
Expand Down
18 changes: 14 additions & 4 deletions src/modules/launcher/Wox.Plugin/PluginPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,29 @@ private bool CreatePluginInstance()
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
{
type = types.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin)));
}
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;
}

Expand All @@ -161,7 +171,7 @@ private bool CreatePluginInstance()
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;
}

Expand Down

0 comments on commit e12e707

Please sign in to comment.