UNPKG

@eventmsg/core

Version:

EventMsgV3 TypeScript library - Core protocol implementation with transport abstraction

1 lines 3.86 kB
{"version":3,"file":"protocol-error.cjs","names":["EventMsgError"],"sources":["../../src/errors/protocol-error.ts"],"sourcesContent":["import { EventMsgError } from \"./event-msg-error.js\";\n\n/**\n * Error related to EventMsgV3 protocol operations (encoding, decoding, validation)\n */\nexport class ProtocolError extends EventMsgError {\n constructor(\n message: string,\n options: {\n context?: Record<string, unknown>;\n solutions?: string[];\n cause?: Error;\n } = {}\n ) {\n super(message, \"PROTOCOL_ERROR\", {\n ...options,\n solutions: options.solutions || [\n \"Check message format\",\n \"Verify protocol specification compliance\",\n \"Review message content\",\n ],\n });\n }\n}\n\n/**\n * Message encoding failed\n */\nexport class EncodingError extends ProtocolError {\n constructor(\n message = \"Failed to encode message\",\n options: {\n context?: Record<string, unknown>;\n cause?: Error;\n } = {}\n ) {\n super(message, {\n ...options,\n solutions: [\n \"Check event name length (≤64 bytes)\",\n \"Check event data length (≤3048 bytes)\",\n \"Verify data is JSON serializable\",\n \"Check for invalid characters\",\n ],\n });\n\n this.code = \"ENCODING_ERROR\";\n }\n}\n\n/**\n * Message decoding failed\n */\nexport class DecodingError extends ProtocolError {\n constructor(\n message = \"Failed to decode message\",\n options: {\n context?: Record<string, unknown>;\n cause?: Error;\n } = {}\n ) {\n super(message, {\n ...options,\n solutions: [\n \"Check message framing (SOH, STX, US, EOT)\",\n \"Verify byte stuffing is correct\",\n \"Check for data corruption\",\n \"Ensure sender uses same protocol version\",\n ],\n });\n\n this.code = \"DECODING_ERROR\";\n }\n}\n\n/**\n * Message validation failed\n */\nexport class ValidationError extends ProtocolError {\n constructor(\n message = \"Message validation failed\",\n options: {\n context?: Record<string, unknown>;\n cause?: Error;\n } = {}\n ) {\n super(message, {\n ...options,\n solutions: [\n \"Check address ranges (0-255)\",\n \"Verify message size limits\",\n \"Check required fields are present\",\n \"Validate data types\",\n ],\n });\n\n this.code = \"VALIDATION_ERROR\";\n }\n}\n\n/**\n * Invalid message format\n */\nexport class InvalidMessageError extends ProtocolError {\n constructor(\n message = \"Invalid message format\",\n options: {\n context?: Record<string, unknown>;\n cause?: Error;\n } = {}\n ) {\n super(message, {\n ...options,\n solutions: [\n \"Check message starts with SOH (0x01)\",\n \"Check message ends with EOT (0x04)\",\n \"Verify minimum message length (10 bytes)\",\n \"Check header is exactly 7 bytes after unstuffing\",\n ],\n });\n\n this.code = \"INVALID_MESSAGE_ERROR\";\n }\n}\n"],"mappings":";;;;;;AAKA,IAAa,gBAAb,cAAmCA,sCAAc;CAC/C,YACE,SACA,UAII,EAAE,EACN;AACA,QAAM,SAAS,kBAAkB;GAC/B,GAAG;GACH,WAAW,QAAQ,aAAa;IAC9B;IACA;IACA;IACD;GACF,CAAC;;;;;;AAON,IAAa,gBAAb,cAAmC,cAAc;CAC/C,YACE,UAAU,4BACV,UAGI,EAAE,EACN;AACA,QAAM,SAAS;GACb,GAAG;GACH,WAAW;IACT;IACA;IACA;IACA;IACD;GACF,CAAC;AAEF,OAAK,OAAO;;;;;;AAOhB,IAAa,gBAAb,cAAmC,cAAc;CAC/C,YACE,UAAU,4BACV,UAGI,EAAE,EACN;AACA,QAAM,SAAS;GACb,GAAG;GACH,WAAW;IACT;IACA;IACA;IACA;IACD;GACF,CAAC;AAEF,OAAK,OAAO;;;;;;AAOhB,IAAa,kBAAb,cAAqC,cAAc;CACjD,YACE,UAAU,6BACV,UAGI,EAAE,EACN;AACA,QAAM,SAAS;GACb,GAAG;GACH,WAAW;IACT;IACA;IACA;IACA;IACD;GACF,CAAC;AAEF,OAAK,OAAO;;;;;;AAOhB,IAAa,sBAAb,cAAyC,cAAc;CACrD,YACE,UAAU,0BACV,UAGI,EAAE,EACN;AACA,QAAM,SAAS;GACb,GAAG;GACH,WAAW;IACT;IACA;IACA;IACA;IACD;GACF,CAAC;AAEF,OAAK,OAAO"}