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 canRerollDefense = false
if (!reroll) continue if (!reroll) continue
defenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll defenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll
await createReactionMessage(defender, { try {
type: "mulligan", await createReactionMessage(defender, {
actorName: defenderName, type: "mulligan",
side: "defense", actorName: defenderName,
oldRoll: oldDefenseRoll, side: "defense",
newRoll: defenseRoll, oldRoll: oldDefenseRoll,
diceResults: reroll.options?.diceResults || [], newRoll: defenseRoll,
D30result: reroll.options?.D30result, diceResults: reroll.options?.diceResults || [],
D30message: reroll.options?.D30message 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 // Apply new D30 result on the restart
if (reroll.options?.D30message) { if (reroll.options?.D30message) {
defenseD30message = reroll.options.D30message defenseD30message = reroll.options.D30message
@@ -753,16 +757,20 @@ Hooks.on("createChatMessage", async (message) => {
canRerollAttack = false canRerollAttack = false
if (!reroll) continue if (!reroll) continue
attackRollFinal = reroll.options?.rollTotal || reroll.total || oldAttackRoll attackRollFinal = reroll.options?.rollTotal || reroll.total || oldAttackRoll
await createReactionMessage(attacker, { try {
type: "mulligan", await createReactionMessage(attacker, {
actorName: attackerName, type: "mulligan",
side: "attack", actorName: attackerName,
oldRoll: oldAttackRoll, side: "attack",
newRoll: attackRollFinal, oldRoll: oldAttackRoll,
diceResults: reroll.options?.diceResults || [], newRoll: attackRollFinal,
D30result: reroll.options?.D30result, diceResults: reroll.options?.diceResults || [],
D30message: reroll.options?.D30message 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 // Apply new D30 result on the restart
if (reroll.options?.D30message) { if (reroll.options?.D30message) {
attackD30message = reroll.options.D30message attackD30message = reroll.options.D30message
+15 -11
View File
@@ -206,17 +206,21 @@ export async function handleAttackBoosted(msg) {
if (!reroll) continue if (!reroll) continue
updatedDefenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll updatedDefenseRoll = reroll.options?.rollTotal || reroll.total || oldDefenseRoll
let newD30message = reroll.options?.D30message || null let newD30message = reroll.options?.D30message || null
const mulliganContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", { try {
type: "mulligan", const mulliganContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", {
actorName: defenderName, type: "mulligan",
side: "defense", actorName: defenderName,
oldRoll: oldDefenseRoll, side: "defense",
newRoll: updatedDefenseRoll, oldRoll: oldDefenseRoll,
diceResults: reroll.options?.diceResults || [], newRoll: updatedDefenseRoll,
D30result: reroll.options?.D30result, diceResults: reroll.options?.diceResults || [],
D30message: newD30message D30result: reroll.options?.D30result,
}) D30message: newD30message
await ChatMessage.create({content: mulliganContent, speaker: ChatMessage.getSpeaker({actor: defender})}) })
await ChatMessage.create({content: mulliganContent, speaker: ChatMessage.getSpeaker({actor: defender})})
} catch(e) {
console.error("Mulligan message creation failed (non-fatal):", e)
}
// Process new D30 bonus dice from the reroll // Process new D30 bonus dice from the reroll
if (newD30message) { if (newD30message) {
defenseD30message = newD30message defenseD30message = newD30message