@eventmsg/core
Version:
EventMsgV3 TypeScript library - Core protocol implementation with transport abstraction
1 lines • 3.22 kB
Source Map (JSON)
{"version":3,"file":"validation-error.cjs","names":["EventMsgError"],"sources":["../../src/errors/validation-error.ts"],"sourcesContent":["import { EventMsgError } from \"./event-msg-error.js\";\n\n/**\n * Error for input validation failures\n */\nexport class ValidationError extends EventMsgError {\n /** Field that failed validation */\n readonly field: string | undefined;\n\n /** Value that was invalid */\n readonly value: unknown;\n\n constructor(\n message: string,\n options: {\n field?: string;\n value?: unknown;\n context?: Record<string, unknown>;\n solutions?: string[];\n cause?: Error;\n } = {}\n ) {\n super(message, \"VALIDATION_ERROR\", {\n ...options,\n context: {\n ...options.context,\n field: options.field,\n value: options.value,\n },\n solutions: [\n \"Check input parameters\",\n \"Verify value ranges and types\",\n \"Review API documentation\",\n ],\n });\n\n this.field = options.field;\n this.value = options.value;\n }\n}\n\n/**\n * Address validation error (0-255 range)\n */\nexport class AddressValidationError extends ValidationError {\n constructor(\n address: number,\n field = \"address\",\n options: {\n context?: Record<string, unknown>;\n solutions?: string[];\n cause?: Error;\n } = {}\n ) {\n super(`Invalid ${field}: ${address}. Must be 0-255`, {\n ...options,\n field,\n value: address,\n solutions: [\n \"Use address in range 0-255\",\n \"Check for negative values\",\n \"Verify address is an integer\",\n ],\n });\n\n this.code = \"ADDRESS_VALIDATION_ERROR\";\n }\n}\n\n/**\n * Message size validation error\n */\nexport class MessageSizeError extends ValidationError {\n constructor(\n size: number,\n maxSize: number,\n field = \"message\",\n options: {\n context?: Record<string, unknown>;\n solutions?: string[];\n cause?: Error;\n } = {}\n ) {\n super(`${field} size ${size} bytes exceeds maximum ${maxSize} bytes`, {\n ...options,\n field,\n value: size,\n context: {\n ...options.context,\n maxSize,\n },\n solutions: [\n `Reduce ${field} size to ${maxSize} bytes or less`,\n \"Consider splitting large messages\",\n \"Use more efficient encoding\",\n ],\n });\n\n this.code = \"MESSAGE_SIZE_ERROR\";\n }\n}\n"],"mappings":";;;;;;AAKA,IAAa,kBAAb,cAAqCA,sCAAc;;CAEjD,AAAS;;CAGT,AAAS;CAET,YACE,SACA,UAMI,EAAE,EACN;AACA,QAAM,SAAS,oBAAoB;GACjC,GAAG;GACH,SAAS;IACP,GAAG,QAAQ;IACX,OAAO,QAAQ;IACf,OAAO,QAAQ;IAChB;GACD,WAAW;IACT;IACA;IACA;IACD;GACF,CAAC;AAEF,OAAK,QAAQ,QAAQ;AACrB,OAAK,QAAQ,QAAQ;;;;;;AAOzB,IAAa,yBAAb,cAA4C,gBAAgB;CAC1D,YACE,SACA,QAAQ,WACR,UAII,EAAE,EACN;AACA,QAAM,WAAW,MAAM,IAAI,QAAQ,kBAAkB;GACnD,GAAG;GACH;GACA,OAAO;GACP,WAAW;IACT;IACA;IACA;IACD;GACF,CAAC;AAEF,OAAK,OAAO;;;;;;AAOhB,IAAa,mBAAb,cAAsC,gBAAgB;CACpD,YACE,MACA,SACA,QAAQ,WACR,UAII,EAAE,EACN;AACA,QAAM,GAAG,MAAM,QAAQ,KAAK,yBAAyB,QAAQ,SAAS;GACpE,GAAG;GACH;GACA,OAAO;GACP,SAAS;IACP,GAAG,QAAQ;IACX;IACD;GACD,WAAW;IACT,UAAU,MAAM,WAAW,QAAQ;IACnC;IACA;IACD;GACF,CAAC;AAEF,OAAK,OAAO"}