From 6b198ecb4731e476e8a1d9e86e798e12e231b897 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Mon, 28 Apr 2025 19:36:54 -0400 Subject: [PATCH] add new error to catch [[floor1_1d3]] and error out correctly --- src/solver/parser.ts | 7 ++++++- src/solver/roller.ts | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/solver/parser.ts b/src/solver/parser.ts index d3f9338..94b9e88 100644 --- a/src/solver/parser.ts +++ b/src/solver/parser.ts @@ -288,7 +288,9 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll // Welp, the unthinkable happened, we hit an error // Split on _ for the error messages that have more info than just their name - const [errorName, errorDetails] = solverError.message.split('_'); + const errorSplits = solverError.message.split('_'); + const errorName = errorSplits.shift(); + const errorDetails = errorSplits.join('_'); let errorMsg = ''; @@ -300,6 +302,9 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll case 'YouNeedAD': errorMsg = 'Formatting Error: Missing die size and count config'; break; + case 'CannotParseDieCount': + errorMsg = `Formatting Error: Cannot parse \`${errorDetails}\` as a number`; + break; case 'DoubleSeparator': errorMsg = `Formatting Error: \`${errorDetails}\` should only be specified once per roll, remove all but one and repeat roll`; break; diff --git a/src/solver/roller.ts b/src/solver/roller.ts index 9972011..59668e8 100644 --- a/src/solver/roller.ts +++ b/src/solver/roller.ts @@ -91,6 +91,8 @@ export const roll = (rollStr: string, modifiers: RollModifiers): RollSet[] => { const rawDC = dPts.shift() || '1'; if (rawDC.includes('.')) { throw new Error('WholeDieCountSizeOnly'); + } else if (rawDC.match(/\D/)) { + throw new Error(`CannotParseDieCount_${rawDC}`); } const tempDC = rawDC.replace(/\D/g, ''); // Rejoin all remaining parts