fix: wrap mulligan message creation in try/catch to prevent handler abort

Even with the partial correctly registered, a template rendering failure
should not abort the entire reroll handler. Without try/catch, the
exception propagates out of the do-while loop and prevents combat result
creation. The reroll value was applied but nothing else happened.
This commit is contained in:
2026-07-05 20:51:26 +02:00
parent 881cecf5b7
commit bfbce9557b
2 changed files with 43 additions and 31 deletions
+28 -20
View File
@@ -551,16 +551,20 @@ Hooks.on("createChatMessage", async (message) => {
canRerollDefense = false
if (!reroll) continue
defenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll
await createReactionMessage(defender, {
type: "mulligan",
actorName: defenderName,
side: "defense",
oldRoll: oldDefenseRoll,
newRoll: defenseRoll,
diceResults: reroll.options?.diceResults || [],
D30result: reroll.options?.D30result,
D30message: reroll.options?.D30message
})
try {
await createReactionMessage(defender, {
type: "mulligan",
actorName: defenderName,
side: "defense",
oldRoll: oldDefenseRoll,
newRoll: defenseRoll,
diceResults: reroll.options?.diceResults || [],
D30result: reroll.options?.D30result,
D30message: reroll.options?.D30message
})
} catch(e) {
console.error("Mulligan message creation failed (non-fatal):", e)
}
// Apply new D30 result on the restart
if (reroll.options?.D30message) {
defenseD30message = reroll.options.D30message
@@ -753,16 +757,20 @@ Hooks.on("createChatMessage", async (message) => {
canRerollAttack = false
if (!reroll) continue
attackRollFinal = reroll.options?.rollTotal || reroll.total || oldAttackRoll
await createReactionMessage(attacker, {
type: "mulligan",
actorName: attackerName,
side: "attack",
oldRoll: oldAttackRoll,
newRoll: attackRollFinal,
diceResults: reroll.options?.diceResults || [],
D30result: reroll.options?.D30result,
D30message: reroll.options?.D30message
})
try {
await createReactionMessage(attacker, {
type: "mulligan",
actorName: attackerName,
side: "attack",
oldRoll: oldAttackRoll,
newRoll: attackRollFinal,
diceResults: reroll.options?.diceResults || [],
D30result: reroll.options?.D30result,
D30message: reroll.options?.D30message
})
} catch(e) {
console.error("Mulligan message creation failed (non-fatal):", e)
}
// Apply new D30 result on the restart
if (reroll.options?.D30message) {
attackD30message = reroll.options.D30message