site-panzai/node_modules/.cache/vite/client/deps/errx.js

41 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2026-11-13 13:57:04 +01:00
// node_modules/errx/dist/index.mjs
var IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[a-z]:[/\\]/i;
var LINE_WITH_FUNCTION_RE = /^\s+at (?<function>.+) \((?<source>[^)]+)\)$/u;
var LINE_WITHOUT_FUNCTION_RE = /^\s+at (?<source>\S+)$/u;
var SOURCE_RE = /^(?<source>.+):(?<line>\d+):(?<column>\d+)$/u;
function captureRawStackTrace() {
if (!Error.captureStackTrace) return;
const stack = new Error();
Error.captureStackTrace(stack);
return stack.stack;
}
function captureStackTrace() {
const stack = captureRawStackTrace();
return stack ? parseRawStackTrace(stack) : [];
}
function parseRawStackTrace(stacktrace) {
const trace = [];
for (const line of stacktrace.split("\n")) {
const match = LINE_WITH_FUNCTION_RE.exec(line) || LINE_WITHOUT_FUNCTION_RE.exec(line);
if (!match?.groups?.source) continue;
const parsed = {
function: void 0,
...match.groups,
source: match.groups.source
};
const parsedSource = SOURCE_RE.exec(parsed.source)?.groups;
if (parsedSource) Object.assign(parsed, parsedSource);
if (IS_ABSOLUTE_RE.test(parsed.source)) parsed.source = `file://${parsed.source}`;
if (parsed.source === import.meta.url) continue;
for (const key of ["line", "column"]) if (parsed[key]) parsed[key] = Number(parsed[key]);
trace.push(parsed);
}
return trace;
}
export {
captureRawStackTrace,
captureStackTrace,
parseRawStackTrace
};
//# sourceMappingURL=errx.js.map