@metamask/kernel-errors
Version:
48 lines • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarshaledOcapErrorStruct = exports.MarshaledErrorStruct = exports.marshaledErrorSchema = exports.ErrorSentinel = exports.ErrorCode = exports.ErrorStruct = void 0;
const superstruct_1 = require("@metamask/superstruct");
const utils_1 = require("@metamask/utils");
/**
* Struct to validate plain {@link Error} objects.
*/
exports.ErrorStruct = (0, superstruct_1.define)('Error', (value) => value instanceof Error);
/**
* Enum defining all error codes for Ocap errors.
*/
exports.ErrorCode = {
StreamReadError: 'STREAM_READ_ERROR',
VatAlreadyExists: 'VAT_ALREADY_EXISTS',
VatDeleted: 'VAT_DELETED',
VatNotFound: 'VAT_NOT_FOUND',
SubclusterNotFound: 'SUBCLUSTER_NOT_FOUND',
};
/**
* A sentinel value used to identify marshaled errors.
*/
exports.ErrorSentinel = '@@MARSHALED_ERROR';
const ErrorCodeStruct = (0, superstruct_1.union)(Object.values(exports.ErrorCode).map((code) => (0, superstruct_1.literal)(code)));
exports.marshaledErrorSchema = {
[exports.ErrorSentinel]: (0, superstruct_1.literal)(true),
message: (0, superstruct_1.string)(),
code: (0, superstruct_1.optional)(ErrorCodeStruct),
data: (0, superstruct_1.optional)(utils_1.JsonStruct),
stack: (0, superstruct_1.optional)((0, superstruct_1.string)()),
};
/**
* Struct to validate marshaled errors.
*/
exports.MarshaledErrorStruct = (0, utils_1.object)({
...exports.marshaledErrorSchema,
cause: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.lazy)(() => exports.MarshaledErrorStruct)])),
});
/**
* Struct to validate marshaled ocap errors.
*/
exports.MarshaledOcapErrorStruct = (0, utils_1.object)({
...exports.marshaledErrorSchema,
code: ErrorCodeStruct,
data: utils_1.JsonStruct,
cause: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.lazy)(() => exports.MarshaledErrorStruct)])),
});
//# sourceMappingURL=constants.cjs.map