fix: isolate listener exceptions in Before/After dispatch
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Frozen;
|
using System.Collections.Frozen;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
@@ -126,9 +127,17 @@ public class CommandHookModSystem : ModSystem
|
|||||||
{
|
{
|
||||||
if (registrations.TryGetValue(commandName, out var mods))
|
if (registrations.TryGetValue(commandName, out var mods))
|
||||||
{
|
{
|
||||||
foreach (var (_, reg) in mods)
|
foreach (var (modId, reg) in mods)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
reg.Before?.Invoke(ref data);
|
reg.Before?.Invoke(ref data);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Mod.Logger.Error("[{0}] Before /{1} threw: {2}", modId, commandName, ex);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.Cancel)
|
if (data.Cancel)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -140,9 +149,20 @@ public class CommandHookModSystem : ModSystem
|
|||||||
internal void FireAfter(string commandName, ref CommandData data, TextCommandResult result)
|
internal void FireAfter(string commandName, ref CommandData data, TextCommandResult result)
|
||||||
{
|
{
|
||||||
if (registrations.TryGetValue(commandName, out var mods))
|
if (registrations.TryGetValue(commandName, out var mods))
|
||||||
foreach (var (_, reg) in mods)
|
{
|
||||||
|
foreach (var (modId, reg) in mods)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
reg.After?.Invoke(ref data, result);
|
reg.After?.Invoke(ref data, result);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Mod.Logger.Error("[{0}] After /{1} threw: {2}", modId, commandName, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SyncWildcard(ICommandHookListener listener, IReadOnlyList<string> commands)
|
private void SyncWildcard(ICommandHookListener listener, IReadOnlyList<string> commands)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user