UNPKG

@metamask/kernel-errors

Version:
32 lines 894 B
import { getSafeJson } from "@metamask/utils"; import { ErrorSentinel } from "../constants.mjs"; import { isOcapError } from "../utils/isOcapError.mjs"; /** * Marshals an error into a {@link MarshaledError}. * * @param error - The error to marshal. * @returns The marshaled error. */ export function marshalError(error) { const output = { [ErrorSentinel]: true, message: error.message, }; if (error.cause) { output.cause = error.cause instanceof Error ? marshalError(error.cause) : JSON.stringify(error.cause); } if (error.stack) { output.stack = error.stack; } if (isOcapError(error)) { output.code = error.code; if (error.data) { output.data = getSafeJson(error.data); } } return harden(output); } //# sourceMappingURL=marshalError.mjs.map