Skip to content
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

Fix plugin exception #3426

Merged
merged 20 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 35 additions & 22 deletions src/Neo/Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,33 +247,46 @@ protected internal virtual void OnSystemLoaded(NeoSystem system)
/// <returns><see langword="true"/> if the <paramref name="message"/> is handled by a plugin; otherwise, <see langword="false"/>.</returns>
public static bool SendMessage(object message)
{
foreach (var plugin in Plugins)
{
if (plugin.IsStopped)
{
continue;
}

return Plugins.Any(plugin =>
bool result;
try
{
try
{
return !plugin.IsStopped &&
plugin.OnMessage(message);
}
catch (Exception ex)
result = plugin.OnMessage(message);
}
catch (Exception ex)
{
Utility.Log(nameof(Plugin), LogLevel.Error, ex);

switch (plugin.ExceptionPolicy)
{
switch (plugin.ExceptionPolicy)
{
case UnhandledExceptionPolicy.StopNode:
throw;
case UnhandledExceptionPolicy.StopPlugin:
plugin.IsStopped = true;
break;
case UnhandledExceptionPolicy.Ignore:
break;
default:
throw new InvalidCastException($"The exception policy {plugin.ExceptionPolicy} is not valid.");
}
Utility.Log(nameof(Plugin), LogLevel.Error, ex);
return false;
case UnhandledExceptionPolicy.StopNode:
throw;
Jim8y marked this conversation as resolved.
Show resolved Hide resolved
case UnhandledExceptionPolicy.StopPlugin:
plugin.IsStopped = true;
break;
case UnhandledExceptionPolicy.Ignore:
break;
shargon marked this conversation as resolved.
Show resolved Hide resolved
default:
throw new InvalidCastException($"The exception policy {plugin.ExceptionPolicy} is not valid.");
Jim8y marked this conversation as resolved.
Show resolved Hide resolved
}

continue; // Skip to the next plugin if an exception is handled
}

if (result)
{
return true;
}
);
}

return false;
}

}
}
Loading