roll-parser - v3.4.0
    Preparing search index...

    Variable NOTATION_ERROR_CODESConst

    NOTATION_ERROR_CODES: readonly [
        "UNEXPECTED_CHARACTER",
        "UNEXPECTED_IDENTIFIER",
        "UNEXPECTED_TOKEN",
        "UNEXPECTED_END",
        "EXPECTED_TOKEN",
        "INVALID_DICE_COUNT",
        "INVALID_DICE_SIDES",
        "DICE_LIMIT_EXCEEDED",
        "DIVISION_BY_ZERO",
        "MODULO_BY_ZERO",
        "INVALID_KEEP_DROP_COUNT",
        "INVALID_KEEP_DROP_TARGET",
        "EXPLODE_LIMIT_EXCEEDED",
        "INVALID_EXPLODE_TARGET",
        "REROLL_LIMIT_EXCEEDED",
        "INVALID_REROLL_TARGET",
        "INVALID_SUCCESS_COUNT_TARGET",
        "INVALID_SORT_TARGET",
        "INVALID_CRIT_THRESHOLD_TARGET",
        "INVALID_DIE_BOUND_TARGET",
        "INVALID_THRESHOLD",
        "NESTED_VERSUS",
        "INVALID_FUNCTION_ARITY",
        "UNDEFINED_VARIABLE",
        "AMBIGUOUS_DICE_CHAIN",
        "MAX_DEPTH_EXCEEDED",
        "NON_FINITE_RESULT",
        "INVALID_NOTATION_TYPE",
    ] = ...

    The subset of ROLL_PARSER_ERROR_CODES the input is answerable for, as a readonly tuple. Runtime counterpart of NotationErrorCode and the list isNotationError matches against.

    A code is in when roll(notation) can raise it for some notation string, given valid options and a valid context — so the right response is to tell whoever supplied the notation that it was rejected. Six codes are out, because for each of them the notation is innocent:

    Calling code: INVALID_EVALUATION_LIMIT (a bad maxDice, maxExplodeIterations, or maxRerollIterations), INVALID_VARIABLE_VALUE (a non-finite entry in context), INCOMPATIBLE_RNG_STATE (a snapshot from another version)

    Library invariant: UNKNOWN_NODE_TYPE, UNKNOWN_OPERATOR, UNKNOWN_FUNCTION — the lexer and parser only ever hand the evaluator shapes it already covers, so reaching one means a hand-built AST or a bug in here.

    Two boundaries are worth knowing. DIVISION_BY_ZERO, MODULO_BY_ZERO, and NON_FINITE_RESULT are in because notation alone reaches them (1d6/0, 10**400), but a context variable reaches them too, so a true is not proof the notation was at fault. INVALID_NOTATION_TYPE is in even though no user can type a non-string: it means the notation you were handed was null or undefined — an absent slash-command option, a missing JSON field — and "give me a dice expression" is the reply that fits.

    import { NOTATION_ERROR_CODES } from 'roll-parser';

    // Prompt copy is only worth writing for the codes a user can actually cause.
    const needsCopy = new Set(NOTATION_ERROR_CODES);