@metamask/kernel-errors
Version:
1 lines • 3.21 kB
Source Map (JSON)
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AACA,uDAO+B;AAC/B,2CAAqD;AAKrD;;GAEG;AACU,QAAA,WAAW,GAAG,IAAA,oBAAM,EAC/B,OAAO,EACP,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,KAAK,CAClC,CAAC;AAEF;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB,eAAe,EAAE,mBAAmB;IACpC,gBAAgB,EAAE,oBAAoB;IACtC,UAAU,EAAE,aAAa;IACzB,WAAW,EAAE,eAAe;IAC5B,kBAAkB,EAAE,sBAAsB;CAClC,CAAC;AAIX;;GAEG;AACU,QAAA,aAAa,GAAG,mBAAmB,CAAC;AAEjD,MAAM,eAAe,GAAG,IAAA,mBAAK,EAC3B,MAAM,CAAC,MAAM,CAAC,iBAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,qBAAO,EAAC,IAAI,CAAC,CAEnD,CACF,CAAC;AAEW,QAAA,oBAAoB,GAAG;IAClC,CAAC,qBAAa,CAAC,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;IAC9B,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,IAAI,EAAE,IAAA,sBAAQ,EAAC,eAAe,CAAC;IAC/B,IAAI,EAAE,IAAA,sBAAQ,EAAC,kBAAU,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACU,QAAA,oBAAoB,GAAG,IAAA,cAAM,EAAC;IACzC,GAAG,4BAAoB;IACvB,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,kBAAI,EAAC,GAAG,EAAE,CAAC,4BAAoB,CAAC,CAAC,CAAC,CAAC;CACrE,CAA2B,CAAC;AAE7B;;GAEG;AACU,QAAA,wBAAwB,GAAG,IAAA,cAAM,EAAC;IAC7C,GAAG,4BAAoB;IACvB,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,kBAAU;IAChB,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,kBAAI,EAAC,GAAG,EAAE,CAAC,4BAAoB,CAAC,CAAC,CAAC,CAAC;CACrE,CAA+B,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport {\n define,\n lazy,\n literal,\n optional,\n string,\n union,\n} from '@metamask/superstruct';\nimport { JsonStruct, object } from '@metamask/utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MarshaledError, MarshaledOcapError } from './types.ts';\n\n/**\n * Struct to validate plain {@link Error} objects.\n */\nexport const ErrorStruct = define<Error>(\n 'Error',\n (value) => value instanceof Error,\n);\n\n/**\n * Enum defining all error codes for Ocap errors.\n */\nexport const ErrorCode = {\n StreamReadError: 'STREAM_READ_ERROR',\n VatAlreadyExists: 'VAT_ALREADY_EXISTS',\n VatDeleted: 'VAT_DELETED',\n VatNotFound: 'VAT_NOT_FOUND',\n SubclusterNotFound: 'SUBCLUSTER_NOT_FOUND',\n} as const;\n\nexport type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\n/**\n * A sentinel value used to identify marshaled errors.\n */\nexport const ErrorSentinel = '@@MARSHALED_ERROR';\n\nconst ErrorCodeStruct = union(\n Object.values(ErrorCode).map((code) => literal(code)) as NonEmptyArray<\n Struct<ErrorCode>\n >,\n);\n\nexport const marshaledErrorSchema = {\n [ErrorSentinel]: literal(true),\n message: string(),\n code: optional(ErrorCodeStruct),\n data: optional(JsonStruct),\n stack: optional(string()),\n};\n\n/**\n * Struct to validate marshaled errors.\n */\nexport const MarshaledErrorStruct = object({\n ...marshaledErrorSchema,\n cause: optional(union([string(), lazy(() => MarshaledErrorStruct)])),\n}) as Struct<MarshaledError>;\n\n/**\n * Struct to validate marshaled ocap errors.\n */\nexport const MarshaledOcapErrorStruct = object({\n ...marshaledErrorSchema,\n code: ErrorCodeStruct,\n data: JsonStruct,\n cause: optional(union([string(), lazy(() => MarshaledErrorStruct)])),\n}) as Struct<MarshaledOcapError>;\n"]}