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
+8
View File
@@ -551,6 +551,7 @@ 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
try {
await createReactionMessage(defender, { await createReactionMessage(defender, {
type: "mulligan", type: "mulligan",
actorName: defenderName, actorName: defenderName,
@@ -561,6 +562,9 @@ Hooks.on("createChatMessage", async (message) => {
D30result: reroll.options?.D30result, D30result: reroll.options?.D30result,
D30message: reroll.options?.D30message 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,6 +757,7 @@ 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
try {
await createReactionMessage(attacker, { await createReactionMessage(attacker, {
type: "mulligan", type: "mulligan",
actorName: attackerName, actorName: attackerName,
@@ -763,6 +768,9 @@ Hooks.on("createChatMessage", async (message) => {
D30result: reroll.options?.D30result, D30result: reroll.options?.D30result,
D30message: reroll.options?.D30message 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
+4
View File
@@ -206,6 +206,7 @@ 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
try {
const mulliganContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", { const mulliganContent = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/reaction-message.hbs", {
type: "mulligan", type: "mulligan",
actorName: defenderName, actorName: defenderName,
@@ -217,6 +218,9 @@ export async function handleAttackBoosted(msg) {
D30message: newD30message 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