one
Version:
One is a new React Framework that makes Vite serve both native and web.
145 lines (143 loc) • 4.3 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var install_error_handlers_exports = {};
__export(install_error_handlers_exports, {
formatErrorSafely: () => formatErrorSafely,
installPrepareStackTraceGuard: () => installPrepareStackTraceGuard,
installSafeUncaughtHandler: () => installSafeUncaughtHandler
});
module.exports = __toCommonJS(install_error_handlers_exports);
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) {}
});
}
//# sourceMappingURL=install-error-handlers.native.js.map