mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-11 19:44:52 +00:00
fix: catch exceptions in handlers directly
Previously, any exceptions that were occuring in a hander's action were being swalled due to being off on another thread. Now, those exceptions are caught and printed out.
This commit is contained in:
@@ -2337,10 +2337,33 @@ namespace PepperDash.Essentials
|
||||
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
Task.Run(
|
||||
() =>
|
||||
handler.Action(message.Type, message.ClientId, message.Content)
|
||||
);
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
handler.Action(message.Type, message.ClientId, message.Content);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogError(
|
||||
"Exception in handler for message type {type}, ClientId {clientId}",
|
||||
message.Type,
|
||||
message.ClientId
|
||||
);
|
||||
this.LogDebug(ex, "Stack Trace: ");
|
||||
}
|
||||
}).ContinueWith(task =>
|
||||
{
|
||||
if (task.IsFaulted && task.Exception != null)
|
||||
{
|
||||
this.LogError(
|
||||
"Unhandled exception in Task for message type {type}, ClientId {clientId}",
|
||||
message.Type,
|
||||
message.ClientId
|
||||
);
|
||||
this.LogDebug(task.Exception.GetBaseException(), "Stack Trace: ");
|
||||
}
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user