-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Plugins: Fail to load a plugin no more prevent loading of all others #11412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugins: Fail to load a plugin no more prevent loading of all others #11412
Conversation
mstv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, have not run
GitUI/Plugin/PluginRegistry.cs
Outdated
| catch | ||
| catch (Exception ex) | ||
| { | ||
| // no-op |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // no-op |
GitUI/Plugin/PluginRegistry.cs
Outdated
| DebugHelpers.Fail("Fail to load a plugin. Error:" + ex.Demystify()); | ||
| return null; | ||
| } | ||
| }).WhereNotNull().ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to allocate, is there?
| }).WhereNotNull().ToArray(); | |
| }).WhereNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.WhereNotNull() is misindeted, it should be under .Select.
|
Nice! I think that'd fix the problem @maraf observed in gitextensions/gitextensions.pluginmanager#73. What was the exception? Which plugins failed? |
Painful session. It took me a lot of time to find the issue as the exception was swallowed (and we don't have a good logging solution). With this fix, the exception now loggued is: As I said above, I think that's due to #11397 where plugins compatible with previous version located in the user folder are not loading and throw. |
I have 2 "plugins" in my user folder: GitExtensions.PluginManager.Plugin & GitExtensions.SolutionRunner.PluginSettings Yes, it could be the reason why @maraf has no plugin loaded. FYI, I don't know why and I have not investigated as the fix was solving the issue but sometimes I had some plugins loaded (3 or 4) but never the same ones. |
b801ac7 to
8454b8e
Compare
|
Will the error message be visible in VS when developing a plugin? |
|
Sounds good! |
|
Updated screenshots in PR description. Otherwise user will copy the error message somewhere else... |
You could have a look #10307. |
You could use Sysinternals DebugView in order to see |
gerhardol
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+2 with comments
8e290e8 to
a5599f7
Compare
RussKie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool!
GitUI/Plugin/FailToLoadPlugin.cs
Outdated
| using GitUI.Properties; | ||
| using GitUIPluginInterfaces; | ||
|
|
||
| namespace GitUI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| namespace GitUI | |
| namespace GitUI; |
GitUI/Plugin/FailToLoadPlugin.cs
Outdated
|
|
||
| namespace GitUI | ||
| { | ||
| public partial class FailToLoadPlugin : IGitPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have to be public?
GitUI/Plugin/FailToLoadPlugin.cs
Outdated
|
|
||
| namespace GitUI | ||
| { | ||
| public partial class FailToLoadPlugin : IGitPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of FailedPluginWrapper as a name?
GitUI/Plugin/FailToLoadPlugin.cs
Outdated
| private readonly Exception _exception; | ||
| [GeneratedRegex("\\\"GitExtensions.([^\"]+)\\\"")] | ||
| private static partial Regex PluginNameRegex(); | ||
| private string _pluginName; | ||
| public FailToLoadPlugin(Exception exception) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] ordering and whitespacing
| private readonly Exception _exception; | |
| [GeneratedRegex("\\\"GitExtensions.([^\"]+)\\\"")] | |
| private static partial Regex PluginNameRegex(); | |
| private string _pluginName; | |
| public FailToLoadPlugin(Exception exception) | |
| [GeneratedRegex("\\\"GitExtensions.([^\"]+)\\\"")] | |
| private static partial Regex PluginNameRegex(); | |
| private readonly Exception _exception; | |
| private string _pluginName; | |
| public FailToLoadPlugin(Exception exception) |
GitUI/Plugin/FailToLoadPlugin.cs
Outdated
| private string _pluginName; | ||
| public FailToLoadPlugin(Exception exception) | ||
| { | ||
| _exception = exception?.Demystify(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need ? here? exception is declared as non-nullable.
Also, the exception must be validated, use ANE.ThrowIfNull().
GitUI/Plugin/FailToLoadPlugin.cs
Outdated
| if (match.Success) | ||
| { | ||
| _pluginName = match.Value; | ||
| Name = TranslatedStrings.FailedToLoadPlugin + ": " + _pluginName.Substring(0, Math.Min(50, match.Value.Length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string interpolation
GitUI/Plugin/FailToLoadPlugin.cs
Outdated
| _exception = exception?.Demystify(); | ||
| try | ||
| { | ||
| Match match = PluginNameRegex().Match(exception.ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception.ToString() is called multiple times.
GitUI/Plugin/PluginRegistry.cs
Outdated
| } | ||
| catch (Exception ex) | ||
| { | ||
| DebugHelpers.Fail("Fail to load a plugin. Error:" + ex.Demystify()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string interpolation
GitUI/Plugin/PluginRegistry.cs
Outdated
| catch (Exception ex) | ||
| { | ||
| // no-op | ||
| DebugHelpers.Fail("Fail to load plugins. Error:" + ex.Demystify()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string interpolation
| return lazy.Value; | ||
| } | ||
| catch (Exception ex) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to get some concrete information, e.g., the plugin assembly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we have no information there provided by the failing code.
I have still changed a little the code here to display the assembly name in the error message if it is extracted successfully from the logs.
a5599f7 to
692f98a
Compare
When a plugin fail to load and an exception is raised, no plugin was added to the `Plugins` collection and so none was added to the menu in the UI. Instead display plugin loading failure in plugin Menu Will mitigate the case where external plugins not (yet) compatible won't prevent internal plugins to load.
692f98a to
dc42b06
Compare
|
Done. |
mstv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, have not run
|
Thank you! |


When a plugin fail to load and an exception is raised, no plugin was added to the
Pluginscollectionand so none was added to the menu in the UI.
Will mitigate the case where external plugins not (yet) compatible won't prevent internal plugins to load.
Screenshots
Before
After
Test methodology
masterwith Rename ISettingsSource -> SettingsSource because it's not interface #11397 )Test environment(s)
Merge strategy
I agree that the maintainer squash merge this PR (if the commit message is clear).
✒️ I contribute this code under The Developer Certificate of Origin.