PHP 8.2.30
Preview: extend-error.js Size: 3.00 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/@jsdevtools/ono/cjs/extend-error.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendError = void 0;
const isomorphic_node_1 = require("./isomorphic.node");
const stack_1 = require("./stack");
const to_json_1 = require("./to-json");
const protectedProps = ["name", "message", "stack"];
/**
 * Extends the new error with the properties of the original error and the `props` object.
 *
 * @param newError - The error object to extend
 * @param originalError - The original error object, if any
 * @param props - Additional properties to add, if any
 */
function extendError(error, originalError, props) {
    let onoError = error;
    extendStack(onoError, originalError);
    // Copy properties from the original error
    if (originalError && typeof originalError === "object") {
        mergeErrors(onoError, originalError);
    }
    // The default `toJSON` method doesn't output props like `name`, `message`, `stack`, etc.
    // So replace it with one that outputs every property of the error.
    onoError.toJSON = to_json_1.toJSON;
    // On Node.js, add support for the `util.inspect()` method
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    if (isomorphic_node_1.addInspectMethod) {
        isomorphic_node_1.addInspectMethod(onoError);
    }
    // Finally, copy custom properties that were specified by the user.
    // These props OVERWRITE any previous props
    if (props && typeof props === "object") {
        Object.assign(onoError, props);
    }
    return onoError;
}
exports.extendError = extendError;
/**
 * Extend the error stack to include its cause
 */
function extendStack(newError, originalError) {
    let stackProp = Object.getOwnPropertyDescriptor(newError, "stack");
    if (stack_1.isLazyStack(stackProp)) {
        stack_1.lazyJoinStacks(stackProp, newError, originalError);
    }
    else if (stack_1.isWritableStack(stackProp)) {
        newError.stack = stack_1.joinStacks(newError, originalError);
    }
}
/**
 * Merges properties of the original error with the new error.
 *
 * @param newError - The error object to extend
 * @param originalError - The original error object, if any
 */
function mergeErrors(newError, originalError) {
    // Get the original error's keys
    // NOTE: We specifically exclude properties that we have already set on the new error.
    // This is _especially_ important for the `stack` property, because this property has
    // a lazy getter in some environments
    let keys = to_json_1.getDeepKeys(originalError, protectedProps);
    // HACK: We have to cast the errors to `any` so we can use symbol indexers.
    // see https://github.com/Microsoft/TypeScript/issues/1863
    let _newError = newError;
    let _originalError = originalError;
    for (let key of keys) {
        if (_newError[key] === undefined) {
            try {
                _newError[key] = _originalError[key];
            }
            catch (e) {
                // This property is read-only, so it can't be copied
            }
        }
    }
}
//# sourceMappingURL=extend-error.js.map

Directory Contents

Dirs: 0 × Files: 30

Name Size Perms Modified Actions
116 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
1.72 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.08 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
482 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
3.00 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.53 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
133 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
1.18 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
420 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
574 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
723 B lrw-r--r-- 2026-02-23 15:45:44
Edit Download
222 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
523 B lrw-r--r-- 2026-02-23 15:45:48
Edit Download
1.70 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
803 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
507 B lrw-r--r-- 2026-02-23 15:45:48
Edit Download
1.93 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.59 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
108 B lrw-r--r-- 2026-02-23 15:45:48
Edit Download
1.56 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.24 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
933 B lrw-r--r-- 2026-02-23 15:45:48
Edit Download
3.27 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
2.17 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
540 B lrw-r--r-- 2026-02-23 15:45:48
Edit Download
1.69 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
1.24 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
8.09 KB lrw-r--r-- 2026-02-23 15:45:48
Edit Download
142 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
115 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).