@metamask/kernel-errors
Version:
51 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamReadError = void 0;
const superstruct_1 = require("@metamask/superstruct");
const BaseError_ts_1 = require("../BaseError.cjs");
const constants_ts_1 = require("../constants.cjs");
class StreamReadError extends BaseError_ts_1.BaseError {
constructor(data, options) {
super(constants_ts_1.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) {
(0, superstruct_1.assert)(marshaledError, this.struct);
return new StreamReadError(marshaledError.data, unmarshalErrorOptions(marshaledError));
}
}
exports.StreamReadError = StreamReadError;
/**
* A superstruct struct for validating marshaled {@link StreamReadError} instances.
*/
StreamReadError.struct = (0, superstruct_1.object)({
...constants_ts_1.marshaledErrorSchema,
code: (0, superstruct_1.literal)(constants_ts_1.ErrorCode.StreamReadError),
data: (0, superstruct_1.union)([
(0, superstruct_1.object)({
vatId: (0, superstruct_1.string)(),
kernelId: (0, superstruct_1.optional)((0, superstruct_1.never)()),
}),
(0, superstruct_1.object)({
vatId: (0, superstruct_1.optional)((0, superstruct_1.never)()),
kernelId: (0, superstruct_1.optional)((0, superstruct_1.never)()),
}),
(0, superstruct_1.object)({
kernelId: (0, superstruct_1.string)(),
vatId: (0, superstruct_1.optional)((0, superstruct_1.never)()),
}),
]),
cause: constants_ts_1.MarshaledErrorStruct,
});
harden(StreamReadError);
//# sourceMappingURL=StreamReadError.cjs.map