UNPKG

@metamask/kernel-errors

Version:
1 lines 2.07 kB
{"version":3,"file":"BaseError.mjs","sourceRoot":"","sources":["../src/BaseError.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,wBAAuB;AAQ3C,MAAM,OAAO,SAAU,SAAQ,KAAK;IAKlC,YACE,IAAe,EACf,OAAe,EACf,UAEI,EAAE;QAEN,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAEvC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAE1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,0CAA0C;QAC1C,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CACrB,eAAmC,EACnC,sBAE0B;QAE1B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;CACF;AACD,MAAM,CAAC,SAAS,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport { ErrorCode } from './constants.ts';\nimport type {\n MarshaledOcapError,\n OcapError,\n ErrorOptionsWithStack,\n MarshaledError,\n} from './types.ts';\n\nexport class BaseError extends Error implements OcapError {\n public readonly code: ErrorCode;\n\n public readonly data: Json | undefined;\n\n constructor(\n code: ErrorCode,\n message: string,\n options: ErrorOptionsWithStack & {\n data?: Json;\n } = {},\n ) {\n const { data, cause, stack } = options;\n\n super(message, { cause });\n\n this.name = this.constructor.name;\n this.code = code;\n this.data = data;\n\n // override the stack property if provided\n if (stack) {\n this.stack = stack;\n }\n\n harden(this);\n }\n\n /**\n * A placeholder for unmarshal functionality. Should be implemented in subclasses.\n *\n * @param _marshaledError - The marshaled error to unmarshal.\n * @param _unmarshalErrorOptions - A function to unmarshal the error options.\n */\n public static unmarshal(\n _marshaledError: MarshaledOcapError,\n _unmarshalErrorOptions: (\n marshaledError: MarshaledError,\n ) => ErrorOptionsWithStack,\n ): BaseError {\n throw new Error('Unmarshal method not implemented');\n }\n}\nharden(BaseError);\n"]}