From 960593eb58f3a6cecfe032e3dd8b97c79f1a7f14 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 21 May 2020 07:48:52 +1000 Subject: [PATCH 1/7] Add handling of reflection type error --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 35486e794..c6c357de0 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -53,10 +53,12 @@ namespace Flow.Launcher.Core.Plugin Log.Exception($"|PluginsLoader.DotNetPlugins|Couldn't load assembly for {metadata.Name}", e); return; } - var types = assembly.GetTypes(); + Type type; try { + var types = assembly.GetTypes(); + type = types.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))); } catch (InvalidOperationException e) @@ -64,6 +66,12 @@ namespace Flow.Launcher.Core.Plugin Log.Exception($"|PluginsLoader.DotNetPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e); return; } + catch (ReflectionTypeLoadException e) + { + Log.Exception($"|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for <{metadata.Name}>", e); + return; + } + IPlugin plugin; try { From ecbcc5923f22766d0b7e73d070451b26c92eb75f Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 21 May 2020 08:47:09 +1000 Subject: [PATCH 2/7] Add error message to inform user of failed plugins --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index c6c357de0..1f6a17573 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -29,6 +29,8 @@ namespace Flow.Launcher.Core.Plugin public static IEnumerable DotNetPlugins(List source) { + var erroredPlugins = new List(); + var plugins = new List(); var metadatas = source.Where(o => AllowedLanguage.IsDotNet(o.Language)); @@ -50,6 +52,8 @@ namespace Flow.Launcher.Core.Plugin } catch (Exception e) { + erroredPlugins.Add(metadata.Name); + Log.Exception($"|PluginsLoader.DotNetPlugins|Couldn't load assembly for {metadata.Name}", e); return; } @@ -63,11 +67,15 @@ namespace Flow.Launcher.Core.Plugin } catch (InvalidOperationException e) { + erroredPlugins.Add(metadata.Name); + Log.Exception($"|PluginsLoader.DotNetPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e); return; } catch (ReflectionTypeLoadException e) { + erroredPlugins.Add(metadata.Name); + Log.Exception($"|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for <{metadata.Name}>", e); return; } @@ -79,6 +87,7 @@ namespace Flow.Launcher.Core.Plugin } catch (Exception e) { + erroredPlugins.Add(metadata.Name); Log.Exception($"|PluginsLoader.DotNetPlugins|Can't create instance for <{metadata.Name}>", e); return; } @@ -93,6 +102,19 @@ namespace Flow.Launcher.Core.Plugin metadata.InitTime += milliseconds; } + + if (erroredPlugins.Count > 0) + { + var errorPluginString = ""; + + erroredPlugins.ForEach(x => errorPluginString += x + Environment.NewLine); + + Task.Run(() => + { + MessageBox.Show($"Uh oh, unable to load plugins:{Environment.NewLine}{errorPluginString}"); + }); + } + return plugins; } From 9bddbe84553e81fbd7b4c07f33d534277e7d92f1 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 21 May 2020 09:02:51 +1000 Subject: [PATCH 3/7] Add references --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 1f6a17573..b1cb8d08d 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -4,8 +4,9 @@ using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Loader; +using System.Threading.Tasks; +using System.Windows; using Flow.Launcher.Infrastructure; -using Flow.Launcher.Infrastructure.Exception; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; From 3a472a34e4789dbd750b5fa4291799a358714913 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 21 May 2020 09:04:28 +1000 Subject: [PATCH 4/7] update --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index b1cb8d08d..51fa5bc9b 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -89,6 +89,7 @@ namespace Flow.Launcher.Core.Plugin catch (Exception e) { erroredPlugins.Add(metadata.Name); + Log.Exception($"|PluginsLoader.DotNetPlugins|Can't create instance for <{metadata.Name}>", e); return; } From 9058afd1b0f381dcb7452f9fd0aab1feebdcf1b7 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 22 May 2020 06:48:03 +1000 Subject: [PATCH 5/7] Update error messages --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 51fa5bc9b..afbc18fdb 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -55,7 +55,7 @@ namespace Flow.Launcher.Core.Plugin { erroredPlugins.Add(metadata.Name); - Log.Exception($"|PluginsLoader.DotNetPlugins|Couldn't load assembly for {metadata.Name}", e); + Log.Exception($"|PluginsLoader.DotNetPlugins|Couldn't load assembly for the plugin: {metadata.Name}", e); return; } @@ -70,14 +70,14 @@ namespace Flow.Launcher.Core.Plugin { erroredPlugins.Add(metadata.Name); - Log.Exception($"|PluginsLoader.DotNetPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e); + Log.Exception($"|PluginsLoader.DotNetPlugins|Can't find the required IPlugin interface for the plugin: <{metadata.Name}>", e); return; } catch (ReflectionTypeLoadException e) { erroredPlugins.Add(metadata.Name); - Log.Exception($"|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for <{metadata.Name}>", e); + Log.Exception($"|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for the plugin: <{metadata.Name}>", e); return; } @@ -90,7 +90,7 @@ namespace Flow.Launcher.Core.Plugin { erroredPlugins.Add(metadata.Name); - Log.Exception($"|PluginsLoader.DotNetPlugins|Can't create instance for <{metadata.Name}>", e); + Log.Exception($"|PluginsLoader.DotNetPlugins|The following plugin has errored and can not be loaded: <{metadata.Name}>", e); return; } #endif @@ -109,11 +109,15 @@ namespace Flow.Launcher.Core.Plugin { var errorPluginString = ""; + var errorMessage = "The following " + + (erroredPlugins.Count > 1 ? "plugins have " : "plugin has ") + + "errored and cannot be loaded:"; + erroredPlugins.ForEach(x => errorPluginString += x + Environment.NewLine); Task.Run(() => { - MessageBox.Show($"Uh oh, unable to load plugins:{Environment.NewLine}{errorPluginString}"); + MessageBox.Show($"{errorMessage}{Environment.NewLine}{errorPluginString}"); }); } From 5cf85b46dedcba1932c282a72e6206e4a15e06df Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 26 May 2020 14:11:20 +1000 Subject: [PATCH 6/7] per comment Add refer to logs message + warning icon --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index afbc18fdb..925083536 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Reflection; using System.Runtime.Loader; using System.Threading.Tasks; -using System.Windows; +using System.Windows.Forms; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; @@ -117,7 +117,10 @@ namespace Flow.Launcher.Core.Plugin Task.Run(() => { - MessageBox.Show($"{errorMessage}{Environment.NewLine}{errorPluginString}"); + MessageBox.Show($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" + + $"{errorPluginString}{Environment.NewLine}{Environment.NewLine} " + + $"Please refer to the logs for more information","", + MessageBoxButtons.OK, MessageBoxIcon.Warning); }); } From 7f23ac49092635b810b34c6b31b9aa3759535f1c Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 26 May 2020 19:10:40 +1000 Subject: [PATCH 7/7] remove unintended space before text --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 925083536..513d85c96 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -118,7 +118,7 @@ namespace Flow.Launcher.Core.Plugin Task.Run(() => { MessageBox.Show($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" + - $"{errorPluginString}{Environment.NewLine}{Environment.NewLine} " + + $"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" + $"Please refer to the logs for more information","", MessageBoxButtons.OK, MessageBoxIcon.Warning); });