Plugins: Disable plugin automatically if it throws an exception

This commit is contained in:
Katy Coe
2020-12-25 22:31:16 +01:00
parent e929d8d97e
commit 1527c9fe17
2 changed files with 5 additions and 1 deletions

View File

@@ -234,7 +234,7 @@ namespace Il2CppInspector.CLI
// Set plugin handlers // Set plugin handlers
PluginManager.ErrorHandler += (s, e) => { PluginManager.ErrorHandler += (s, e) => {
Console.Error.WriteLine($"The plugin {e.Error.Plugin.Name} encountered an error while executing {e.Error.Operation}: {e.Error.Exception.Message}." Console.Error.WriteLine($"The plugin {e.Error.Plugin.Name} encountered an error while executing {e.Error.Operation}: {e.Error.Exception.Message}."
+ " The application will continue but may not behave as expected."); + " Plugin has been disabled.");
}; };
PluginManager.StatusHandler += (s, e) => { PluginManager.StatusHandler += (s, e) => {

View File

@@ -262,6 +262,10 @@ namespace Il2CppInspector
break; break;
} }
catch (Exception ex) { catch (Exception ex) {
// Disable failing plugin
Plugins[plugin.Id].Enabled = false;
// Forward error to error handler
eventInfo.Error = new PluginErrorEventArgs { Plugin = plugin, Exception = ex, Operation = typeof(I).Name }; eventInfo.Error = new PluginErrorEventArgs { Plugin = plugin, Exception = ex, Operation = typeof(I).Name };
ErrorHandler?.Invoke(AsInstance, eventInfo); ErrorHandler?.Invoke(AsInstance, eventInfo);
} }