UNPKG

@tapjs/error-serdes

Version:

Port of node's error_serdes.js to userland, plus test message streaming

37 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deserializeError = void 0; // This module is more or less a direct port of the deserialization logic // from node's lib/internal/error_serdes module, with primordials removed. const v8_1 = require("v8"); const constants_js_1 = require("./constants.js"); const deserializeError = (error) => { switch (error[0]) { case constants_js_1.kSerializedError: { // serialized Error const { properties, constructor } = (0, v8_1.deserialize)(error.subarray(1)); const ctor = constants_js_1.errors[constructor]; if ('cause' in properties && 'value' in properties.cause) { properties.cause.value = (0, exports.deserializeError)(properties.cause.value); } return Object.create(ctor.prototype, properties); } case constants_js_1.kSerializedObject: { return (0, v8_1.deserialize)(error.subarray(1)); } case constants_js_1.kInspectedError: { return error.subarray(1).toString('utf8'); } case constants_js_1.kInspectedSymbol: { return Symbol.for(error.subarray(1 + 'Symbol('.length, error.length - 1).toString()); } case constants_js_1.kCustomInspectedObject: { const s = error.subarray(1).toString(); return Object.assign(Object.create(null), { [Symbol.for('nodejs.util.inspect.custom')]: () => s, }); } } }; exports.deserializeError = deserializeError; //# sourceMappingURL=deserialize.js.map