@metamask/kernel-errors
Version:
1 lines • 3.3 kB
Source Map (JSON)
{"version":3,"file":"StreamReadError.mjs","sourceRoot":"","sources":["../../src/errors/StreamReadError.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,OAAO,EACP,KAAK,EACL,MAAM,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACN,8BAA8B;AAE/B,OAAO,EAAE,SAAS,EAAE,yBAAwB;AAC5C,OAAO,EACL,oBAAoB,EACpB,SAAS,EACT,oBAAoB,EACrB,yBAAwB;AAOzB,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,IAAyB,EAAE,OAA+B;QACpE,KAAK,CAAC,SAAS,CAAC,eAAe,EAAE,+BAA+B,EAAE;YAChE,GAAG,OAAO;YACV,IAAI;SACL,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;IAyBD;;;;;;OAMG;IACI,MAAM,CAAC,SAAS,CACrB,cAAkC,EAClC,qBAE0B;QAE1B,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,IAAI,eAAe,CACxB,cAAc,CAAC,IAA2B,EAC1C,qBAAqB,CAAC,cAAc,CAA2B,CAChE,CAAC;IACJ,CAAC;;AAzCD;;GAEG;AACW,sBAAM,GAAG,MAAM,CAAC;IAC5B,GAAG,oBAAoB;IACvB,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC;IACxC,IAAI,EAAE,KAAK,CAAC;QACV,MAAM,CAAC;YACL,KAAK,EAAE,MAAM,EAAE;YACf,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;SAC5B,CAAC;QACF,MAAM,CAAC;YACL,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;YACxB,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;SAC5B,CAAC;QACF,MAAM,CAAC;YACL,QAAQ,EAAE,MAAM,EAAE;YAClB,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;SACzB,CAAC;KACH,CAAC;IACF,KAAK,EAAE,oBAAoB;CAC5B,CAAC,CAAC;AAsBL,MAAM,CAAC,eAAe,CAAC,CAAC","sourcesContent":["import {\n assert,\n literal,\n never,\n object,\n optional,\n string,\n union,\n} from '@metamask/superstruct';\n\nimport { BaseError } from '../BaseError.ts';\nimport {\n marshaledErrorSchema,\n ErrorCode,\n MarshaledErrorStruct,\n} from '../constants.ts';\nimport type { ErrorOptionsWithStack, MarshaledOcapError } from '../types.ts';\n\ntype StreamReadErrorData = { vatId: string } | { kernelId: string };\ntype StreamReadErrorOptions = Required<ErrorOptions> &\n Pick<ErrorOptionsWithStack, 'stack'>;\n\nexport class StreamReadError extends BaseError {\n constructor(data: StreamReadErrorData, options: StreamReadErrorOptions) {\n super(ErrorCode.StreamReadError, 'Unexpected stream read error.', {\n ...options,\n data,\n });\n harden(this);\n }\n\n /**\n * A superstruct struct for validating marshaled {@link StreamReadError} instances.\n */\n public static struct = object({\n ...marshaledErrorSchema,\n code: literal(ErrorCode.StreamReadError),\n data: union([\n object({\n vatId: string(),\n kernelId: optional(never()),\n }),\n object({\n vatId: optional(never()),\n kernelId: optional(never()),\n }),\n object({\n kernelId: string(),\n vatId: optional(never()),\n }),\n ]),\n cause: MarshaledErrorStruct,\n });\n\n /**\n * Unmarshals a {@link MarshaledError} into a {@link StreamReadError}.\n *\n * @param marshaledError - The marshaled error to unmarshal.\n * @param unmarshalErrorOptions - A function to unmarshal the error options.\n * @returns The unmarshaled error.\n */\n public static unmarshal(\n marshaledError: MarshaledOcapError,\n unmarshalErrorOptions: (\n marshaledError: MarshaledOcapError,\n ) => ErrorOptionsWithStack,\n ): StreamReadError {\n assert(marshaledError, this.struct);\n return new StreamReadError(\n marshaledError.data as StreamReadErrorData,\n unmarshalErrorOptions(marshaledError) as StreamReadErrorOptions,\n );\n }\n}\nharden(StreamReadError);\n"]}