@metamask/kernel-errors
Version:
1 lines • 3.25 kB
Source Map (JSON)
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,MAAM,EACN,KAAK,EACN,8BAA8B;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,wBAAwB;AAKrD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAC/B,OAAO,EACP,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,KAAK,CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,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;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAEjD,MAAM,eAAe,GAAG,KAAK,CAC3B,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAEnD,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE;IACjB,IAAI,EAAE,QAAQ,CAAC,eAAe,CAAC;IAC/B,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC;IAC1B,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;IACzC,GAAG,oBAAoB;IACvB,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;CACrE,CAA2B,CAAC;AAE7B;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;IAC7C,GAAG,oBAAoB;IACvB,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,oBAAoB,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"]}