@eventmsg/core
Version:
EventMsgV3 TypeScript library - Core protocol implementation with transport abstraction
1 lines • 3.31 kB
Source Map (JSON)
{"version":3,"file":"event-msg-error.cjs","names":[],"sources":["../../src/errors/event-msg-error.ts"],"sourcesContent":["/**\n * Base error class for all EventMsg-related errors.\n * Provides consistent error handling with context and solutions.\n */\nexport class EventMsgError extends Error {\n /** Error code for programmatic handling */\n code: string;\n\n /** Additional context about the error */\n readonly context: Record<string, unknown> | undefined;\n\n /** Suggested solutions for the error */\n readonly solutions: string[];\n\n /** Original error that caused this error */\n readonly cause: Error | undefined;\n\n constructor(\n message: string,\n code: string,\n options: {\n context?: Record<string, unknown>;\n solutions?: string[];\n cause?: Error;\n } = {}\n ) {\n super(message);\n\n this.name = this.constructor.name;\n this.code = code;\n this.context = options.context;\n this.solutions = options.solutions || [];\n this.cause = options.cause;\n\n // Maintain proper stack trace in V8\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n /**\n * Get a detailed error message including context and solutions\n */\n getDetailedMessage(): string {\n let details = `${this.name}: ${this.message}`;\n\n if (this.code) {\n details += ` (${this.code})`;\n }\n\n if (this.context && Object.keys(this.context).length > 0) {\n details += \"\\nContext:\";\n for (const [key, value] of Object.entries(this.context)) {\n details += `\\n ${key}: ${JSON.stringify(value)}`;\n }\n }\n\n if (this.solutions.length > 0) {\n details += \"\\nSuggested solutions:\";\n for (const solution of this.solutions) {\n details += `\\n • ${solution}`;\n }\n }\n\n if (this.cause) {\n details += `\\nCaused by: ${this.cause.message}`;\n }\n\n return details;\n }\n\n /**\n * Convert error to JSON for logging/serialization\n */\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n context: this.context,\n solutions: this.solutions,\n stack: this.stack,\n cause: this.cause\n ? {\n name: this.cause.name,\n message: this.cause.message,\n }\n : undefined,\n };\n }\n}\n"],"mappings":";;;;;;AAIA,IAAa,gBAAb,cAAmC,MAAM;;CAEvC;;CAGA,AAAS;;CAGT,AAAS;;CAGT,AAAS;CAET,YACE,SACA,MACA,UAII,EAAE,EACN;AACA,QAAM,QAAQ;AAEd,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,OAAO;AACZ,OAAK,UAAU,QAAQ;AACvB,OAAK,YAAY,QAAQ,aAAa,EAAE;AACxC,OAAK,QAAQ,QAAQ;AAGrB,MAAI,MAAM,kBACR,OAAM,kBAAkB,MAAM,KAAK,YAAY;;;;;CAOnD,qBAA6B;EAC3B,IAAI,UAAU,GAAG,KAAK,KAAK,IAAI,KAAK;AAEpC,MAAI,KAAK,KACP,YAAW,KAAK,KAAK,KAAK;AAG5B,MAAI,KAAK,WAAW,OAAO,KAAK,KAAK,QAAQ,CAAC,SAAS,GAAG;AACxD,cAAW;AACX,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,QAAQ,CACrD,YAAW,OAAO,IAAI,IAAI,KAAK,UAAU,MAAM;;AAInD,MAAI,KAAK,UAAU,SAAS,GAAG;AAC7B,cAAW;AACX,QAAK,MAAM,YAAY,KAAK,UAC1B,YAAW,SAAS;;AAIxB,MAAI,KAAK,MACP,YAAW,gBAAgB,KAAK,MAAM;AAGxC,SAAO;;;;;CAMT,SAAkC;AAChC,SAAO;GACL,MAAM,KAAK;GACX,SAAS,KAAK;GACd,MAAM,KAAK;GACX,SAAS,KAAK;GACd,WAAW,KAAK;GAChB,OAAO,KAAK;GACZ,OAAO,KAAK,QACR;IACE,MAAM,KAAK,MAAM;IACjB,SAAS,KAAK,MAAM;IACrB,GACD;GACL"}