UNPKG

@metamask/kernel-errors

Version:
45 lines 1.46 kB
import { define, lazy, literal, optional, string, union } from "@metamask/superstruct"; import { JsonStruct, object } from "@metamask/utils"; /** * Struct to validate plain {@link Error} objects. */ export const ErrorStruct = define('Error', (value) => value instanceof Error); /** * Enum defining all error codes for Ocap errors. */ export const 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. */ export const ErrorSentinel = '@@MARSHALED_ERROR'; const ErrorCodeStruct = union(Object.values(ErrorCode).map((code) => literal(code))); export const marshaledErrorSchema = { [ErrorSentinel]: literal(true), message: string(), code: optional(ErrorCodeStruct), data: optional(JsonStruct), stack: optional(string()), }; /** * Struct to validate marshaled errors. */ export const MarshaledErrorStruct = object({ ...marshaledErrorSchema, cause: optional(union([string(), lazy(() => MarshaledErrorStruct)])), }); /** * Struct to validate marshaled ocap errors. */ export const MarshaledOcapErrorStruct = object({ ...marshaledErrorSchema, code: ErrorCodeStruct, data: JsonStruct, cause: optional(union([string(), lazy(() => MarshaledErrorStruct)])), }); //# sourceMappingURL=constants.mjs.map