one
Version:
One is a new React Framework that makes Vite serve both native and web.
115 lines (114 loc) • 3.25 kB
JavaScript
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
var userPrepare;
var depth = 0;
var restoreTrail = [];
function defaultFormat(error, stack) {
var _ref, _ref1;
var name = (_ref = error === null || error === void 0 ? void 0 : error.name) !== null && _ref !== void 0 ? _ref : "Error";
var message = (_ref1 = error === null || error === void 0 ? void 0 : error.message) !== null && _ref1 !== void 0 ? _ref1 : "";
var head = `${name}: ${message}`;
try {
var lines = stack.map(function (frame) {
try {
return ` at ${frame}`;
} catch (unused) {
return " at <frame>";
}
});
return `${head}
${lines.join("\n")}`;
} catch (unused) {
return head;
}
}
function guardedPrepare(error, stack) {
if (depth > 0) return defaultFormat(error, stack);
if (typeof userPrepare !== "function") return defaultFormat(error, stack);
depth++;
try {
return userPrepare(error, stack);
} catch (unused) {
return defaultFormat(error, stack);
} finally {
depth--;
}
}
var installed = false;
function installPrepareStackTraceGuard() {
if (installed) return;
installed = true;
var existing = Error.prepareStackTrace;
if (typeof existing === "function" && existing !== guardedPrepare) {
userPrepare = existing;
}
Object.defineProperty(Error, "prepareStackTrace", {
configurable: true,
get() {
return guardedPrepare;
},
set(value) {
if (value === guardedPrepare) {
if (restoreTrail.length > 0) {
userPrepare = restoreTrail.pop();
}
return;
}
restoreTrail.push(userPrepare);
userPrepare = typeof value === "function" ? value : void 0;
}
});
}
function formatErrorSafely(err) {
var prevPrepare = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
try {
if (_instanceof(err, Error)) {
var stack = "";
try {
var _err_stack;
stack = (_err_stack = err.stack) !== null && _err_stack !== void 0 ? _err_stack : "";
} catch (unused) {}
if (stack) return stack;
var name = err.name || "Error";
var message = err.message || "";
return `${name}: ${message}`;
}
return String(err);
} catch (unused) {
try {
return String(err);
} catch (unused2) {
return "<unprintable error>";
}
} finally {
Error.prepareStackTrace = prevPrepare;
}
}
function installSafeUncaughtHandler(label) {
installPrepareStackTraceGuard();
process.on("uncaughtException", function (err) {
try {
var formatted = formatErrorSafely(err);
process.stderr.write(`[${label}] uncaught exception
${formatted}
`);
} catch (unused) {}
process.exit(1);
});
process.on("unhandledRejection", function (reason) {
try {
var formatted = formatErrorSafely(reason);
process.stderr.write(`[${label}] unhandled rejection
${formatted}
`);
} catch (unused) {}
});
}
export { formatErrorSafely, installPrepareStackTraceGuard, installSafeUncaughtHandler };
//# sourceMappingURL=install-error-handlers.native.js.map