From f4fcb097c34aae37223b620242866b6b885fb539 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Thu, 26 Jun 2025 03:39:48 -0400 Subject: [PATCH] improve the YouNeedAD error message --- src/artigen/dice/getRollConf.ts | 4 ++-- src/artigen/utils/translateError.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/artigen/dice/getRollConf.ts b/src/artigen/dice/getRollConf.ts index 4eef389..aee3f5a 100644 --- a/src/artigen/dice/getRollConf.ts +++ b/src/artigen/dice/getRollConf.ts @@ -65,7 +65,7 @@ export const getRollConf = (rollStr: string): RollConf => { // If the dPts is not long enough, throw error if (dPts.length < 2) { - throw new Error('YouNeedAD'); + throw new Error(`YouNeedAD_${rollStr}`); } // Fill out the die count, first item will either be an int or empty string, short circuit execution will take care of replacing the empty string with a 1 @@ -153,7 +153,7 @@ export const getRollConf = (rollStr: string): RollConf => { } if (!rollConf.dieCount || !rollConf.dieSize) { - throw new Error('YouNeedAD'); + throw new Error(`YouNeedAD_${rollStr}`); } loggingEnabled && log(LT.LOG, `${getLoopCount()} Handling ${rollConf.type} ${rollStr} | Parsed Die Count: ${rollConf.dieCount}`); diff --git a/src/artigen/utils/translateError.ts b/src/artigen/utils/translateError.ts index fa63862..1401d5a 100644 --- a/src/artigen/utils/translateError.ts +++ b/src/artigen/utils/translateError.ts @@ -15,10 +15,15 @@ export const translateError = (solverError: Error): [string, string] => { // Translate the errorName to a specific errorMsg switch (errorName) { case 'WholeDieCountSizeOnly': - errorMsg = 'Error: Die Size and Die Count must be whole numbers'; + errorMsg = 'Error: Die Size and Die Count must be positive whole numbers'; break; case 'YouNeedAD': - errorMsg = 'Formatting Error: Missing die size and count config'; + errorMsg = `Error: Attempted to parse \`${errorDetails}\` as a dice configuration, `; + if (errorDetails.includes('d')) { + errorMsg += '`d` was found, but the die size and/or count were missing or zero when they should be a positive whole number'; + } else { + errorMsg += '`d` was not found in the dice config for specifying die size and/or count'; + } break; case 'CannotParseDieCount': errorMsg = `Formatting Error: Cannot parse \`${errorDetails}\` as a number`;