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

import { addInspectMethod } from "./isomorphic.node";
import { isLazyStack, isWritableStack, joinStacks, lazyJoinStacks } from "./stack";
import { getDeepKeys, toJSON } from "./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
 */
export 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 = toJSON;
    // On Node.js, add support for the `util.inspect()` method
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    if (addInspectMethod) {
        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;
}
/**
 * Extend the error stack to include its cause
 */
function extendStack(newError, originalError) {
    let stackProp = Object.getOwnPropertyDescriptor(newError, "stack");
    if (isLazyStack(stackProp)) {
        lazyJoinStacks(stackProp, newError, originalError);
    }
    else if (isWritableStack(stackProp)) {
        newError.stack = 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 = 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.57 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.20 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
2.84 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.64 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
374 B lrw-r--r-- 2026-02-23 15:45:44
Edit Download
458 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
604 B lrw-r--r-- 2026-02-23 15:45:44
Edit Download
239 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.53 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
853 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.70 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.60 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.46 KB lrw-r--r-- 2026-02-23 15:45:44
Edit Download
1.29 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
2.98 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
2.14 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.53 KB lrw-r--r-- 2026-02-23 15:45:46
Edit Download
1.22 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
65 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download
141 B lrw-r--r-- 2026-02-23 15:45:46
Edit Download

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