/** * Centralized error codes for all RANDSUM errors. * Use these constants instead of raw strings for consistency. */ declare const ERROR_CODES: Record & { readonly INVALID_NOTATION: "INVALID_NOTATION"; readonly MODIFIER_ERROR: "MODIFIER_ERROR"; readonly VALIDATION_ERROR: "VALIDATION_ERROR"; readonly ROLL_ERROR: "ROLL_ERROR"; }; type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES] | (string & Record); /** * Optional structured context for a RANDSUM error. * * Populated by throw sites that know additional details about the failure. * Consumers may read any of these fields to present richer diagnostics * (e.g. highlight the offending character in an input, show which option * field failed validation, log the raw value that triggered the error). * * All fields are optional — throw sites only include what they know. */ interface ErrorContext { /** Dotted path to the offending option field, e.g. `'quantity'`, `'modifiers.drop.lowest'`. */ readonly path?: string; /** The offending value (kept as `unknown` so callers type-narrow before use). */ readonly value?: unknown; /** The notation string associated with the failure, when relevant. */ readonly notation?: string; /** Zero-indexed character offset in the notation string, when known. */ readonly position?: number; } /** * Base error class for all RANDSUM errors. * All custom errors in the RANDSUM ecosystem should extend this class. */ declare class RandsumError extends Error { readonly code: ErrorCode; readonly context: ErrorContext | undefined; constructor(message: string, code: ErrorCode, context?: ErrorContext); } /** * Error thrown when a string is not valid dice notation. */ declare class NotationParseError extends RandsumError { readonly suggestion: string | undefined; constructor(notation: string, reason: string, suggestion?: string, context?: ErrorContext); } declare class ModifierError extends RandsumError { constructor(modifierType: string, reason: string, context?: ErrorContext); } declare class ValidationError extends RandsumError { constructor(message: string, context?: ErrorContext); } declare class RollError extends RandsumError { constructor(message: string, context?: ErrorContext); } export { ValidationError, RollError, RandsumError, NotationParseError, ModifierError, ErrorContext, ErrorCode, ERROR_CODES };