UNPKG

@metamask/kernel-errors

Version:
47 lines 1.61 kB
import { assert, literal, never, object, optional, string, union } from "@metamask/superstruct"; import { BaseError } from "../BaseError.mjs"; import { marshaledErrorSchema, ErrorCode, MarshaledErrorStruct } from "../constants.mjs"; export class StreamReadError extends BaseError { constructor(data, options) { super(ErrorCode.StreamReadError, 'Unexpected stream read error.', { ...options, data, }); harden(this); } /** * Unmarshals a {@link MarshaledError} into a {@link StreamReadError}. * * @param marshaledError - The marshaled error to unmarshal. * @param unmarshalErrorOptions - A function to unmarshal the error options. * @returns The unmarshaled error. */ static unmarshal(marshaledError, unmarshalErrorOptions) { assert(marshaledError, this.struct); return new StreamReadError(marshaledError.data, unmarshalErrorOptions(marshaledError)); } } /** * A superstruct struct for validating marshaled {@link StreamReadError} instances. */ StreamReadError.struct = object({ ...marshaledErrorSchema, code: literal(ErrorCode.StreamReadError), data: union([ object({ vatId: string(), kernelId: optional(never()), }), object({ vatId: optional(never()), kernelId: optional(never()), }), object({ kernelId: string(), vatId: optional(never()), }), ]), cause: MarshaledErrorStruct, }); harden(StreamReadError); //# sourceMappingURL=StreamReadError.mjs.map