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 validcontext— 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 badmaxDice,maxExplodeIterations, ormaxRerollIterations),INVALID_VARIABLE_VALUE(a non-finite entry incontext),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, andNON_FINITE_RESULTare in because notation alone reaches them (1d6/0,10**400), but acontextvariable reaches them too, so atrueis not proof the notation was at fault.INVALID_NOTATION_TYPEis in even though no user can type a non-string: it means thenotationyou were handed wasnullorundefined— an absent slash-command option, a missing JSON field — and "give me a dice expression" is the reply that fits.