@visulima/error 5.0.3 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/code-frame/index.js +125 -6
- package/dist/error/index.js +8 -1
- package/dist/index.js +16 -1
- package/dist/packem_shared/NonError-D5FGLYKY.js +8 -0
- package/dist/packem_shared/addKnownErrorConstructor-s_3SsXtQ.js +30 -0
- package/dist/packem_shared/aiFinder-HftEgsry.js +277 -0
- package/dist/packem_shared/aiSolutionResponse-CJBMLS9t.js +34 -0
- package/dist/packem_shared/captureRawStackTrace-ySw7cU0U.js +10 -0
- package/dist/packem_shared/deserializeError-E0VQnnm0.js +116 -0
- package/dist/packem_shared/errorHintFinder-DEaeRnRW.js +21 -0
- package/dist/packem_shared/formatStackFrameLine-D3_6oSWZ.js +24 -0
- package/dist/packem_shared/getErrorCauses-DpUsmuqw.js +43 -0
- package/dist/packem_shared/index-y_UPkY2Z.js +9 -0
- package/dist/packem_shared/indexToLineColumn-Bg8UW1bU.js +50 -0
- package/dist/packem_shared/isVisulimaError-DA7QsCxH.js +34 -0
- package/dist/packem_shared/parseStacktrace-oQvk7wYp.js +273 -0
- package/dist/packem_shared/renderError-C30PRFtU.js +206 -0
- package/dist/packem_shared/ruleBasedFinder-C2F8rQ30.js +207 -0
- package/dist/packem_shared/serializeError-BZ62KiYZ.js +142 -0
- package/dist/solution/ai/ai-prompt.js +13 -7
- package/dist/solution/ai/index.js +3 -1
- package/dist/solution/index.js +2 -1
- package/dist/stacktrace/index.js +2 -1
- package/package.json +1 -1
- package/dist/packem_shared/NonError-CS10kwil.js +0 -1
- package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.js +0 -1
- package/dist/packem_shared/aiFinder-DPoqj12B.js +0 -1
- package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.js +0 -10
- package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.js +0 -1
- package/dist/packem_shared/deserializeError-BJM8Kd6G.js +0 -1
- package/dist/packem_shared/errorHintFinder-C_g0nvml.js +0 -2
- package/dist/packem_shared/formatStackFrameLine-iU54KA81.js +0 -2
- package/dist/packem_shared/getErrorCauses-geeK5cwE.js +0 -1
- package/dist/packem_shared/index-CLFYRLyq.js +0 -1
- package/dist/packem_shared/indexToLineColumn-B1F7aNZh.js +0 -1
- package/dist/packem_shared/isVisulimaError-jVZgumOU.js +0 -1
- package/dist/packem_shared/parseStacktrace-Dnxnc4PL.js +0 -2
- package/dist/packem_shared/renderError-ZMlMvw1N.js +0 -18
- package/dist/packem_shared/ruleBasedFinder-P88d0gpK.js +0 -34
- package/dist/packem_shared/serializeError-CTpDr3CL.js +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const errorHintFinder = {
|
|
2
|
+
handle: async (error) => {
|
|
3
|
+
if (error.hint === void 0 || error.hint === null) {
|
|
4
|
+
return void 0;
|
|
5
|
+
}
|
|
6
|
+
if (typeof error.hint === "string" && error.hint !== "") {
|
|
7
|
+
return { body: error.hint };
|
|
8
|
+
}
|
|
9
|
+
if (typeof error.hint === "object" && typeof error.hint.body === "string") {
|
|
10
|
+
return error.hint;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(error.hint)) {
|
|
13
|
+
return { body: error.hint.join("\n") };
|
|
14
|
+
}
|
|
15
|
+
return void 0;
|
|
16
|
+
},
|
|
17
|
+
name: "errorHint",
|
|
18
|
+
priority: 1
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { errorHintFinder as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const formatStackFrameLine = (frame) => {
|
|
2
|
+
const method = frame.methodName && frame.methodName !== "<unknown>" ? `${frame.methodName} ` : "";
|
|
3
|
+
const file = frame.file ?? "<unknown>";
|
|
4
|
+
const line = frame.line ?? 0;
|
|
5
|
+
const column = frame.column ?? 0;
|
|
6
|
+
if (method.trim()) {
|
|
7
|
+
return ` at ${method}(${file}:${line}:${column})`;
|
|
8
|
+
}
|
|
9
|
+
return ` at ${file}:${line}:${column}`;
|
|
10
|
+
};
|
|
11
|
+
const formatStacktrace = (frames, options) => {
|
|
12
|
+
const lines = [];
|
|
13
|
+
if (options?.header && (options.header.name || options.header.message)) {
|
|
14
|
+
const headerName = String(options.header.name || "Error");
|
|
15
|
+
const headerMessage = String(options.header.message || "");
|
|
16
|
+
lines.push(`${headerName}${headerMessage ? ": " : ""}${headerMessage}`);
|
|
17
|
+
}
|
|
18
|
+
for (const frame of frames) {
|
|
19
|
+
lines.push(formatStackFrameLine(frame));
|
|
20
|
+
}
|
|
21
|
+
return lines.join("\n");
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { formatStackFrameLine, formatStacktrace };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
inspect
|
|
22
|
+
} = __cjs_getBuiltinModule("node:util");
|
|
23
|
+
|
|
24
|
+
const getErrorCauses = (error) => {
|
|
25
|
+
const seen = /* @__PURE__ */ new Set();
|
|
26
|
+
const causes = [];
|
|
27
|
+
let currentError = error;
|
|
28
|
+
while (currentError) {
|
|
29
|
+
if (seen.has(currentError)) {
|
|
30
|
+
console.error(`Circular reference detected in error causes: ${inspect(error)}`);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
causes.push(currentError);
|
|
34
|
+
seen.add(currentError);
|
|
35
|
+
if (!currentError.cause) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
currentError = currentError.cause;
|
|
39
|
+
}
|
|
40
|
+
return causes;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { getErrorCauses as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function isPlainObject(value) {
|
|
2
|
+
if (typeof value !== "object" || value === null) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const prototype = Object.getPrototypeOf(value);
|
|
6
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { isPlainObject as i };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const binarySearch = (element, array) => {
|
|
2
|
+
let m = 0;
|
|
3
|
+
let n = array.length - 2;
|
|
4
|
+
while (m < n) {
|
|
5
|
+
const key = m + (n - m >> 1);
|
|
6
|
+
if (element < array[key]) {
|
|
7
|
+
n = key - 1;
|
|
8
|
+
} else if (element >= array[key + 1]) {
|
|
9
|
+
m = key + 1;
|
|
10
|
+
} else {
|
|
11
|
+
m = key;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return m;
|
|
16
|
+
};
|
|
17
|
+
const getLineStartIndexes = (string_) => (
|
|
18
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
19
|
+
string_.split(/\n|\r(?!\n)/).reduce(
|
|
20
|
+
(accumulator, current) => {
|
|
21
|
+
accumulator.push(accumulator.at(-1) + current.length + 1);
|
|
22
|
+
return accumulator;
|
|
23
|
+
},
|
|
24
|
+
[0]
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
const indexToLineColumn = (input, index, options) => {
|
|
28
|
+
const skipChecks = options?.skipChecks ?? false;
|
|
29
|
+
if (!skipChecks && (!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
|
|
30
|
+
return { column: 0, line: 0 };
|
|
31
|
+
}
|
|
32
|
+
if (!skipChecks && (typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
|
|
33
|
+
return { column: 0, line: 0 };
|
|
34
|
+
}
|
|
35
|
+
if (typeof input === "string") {
|
|
36
|
+
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
37
|
+
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
38
|
+
return {
|
|
39
|
+
column: index - startIndexesOfEachLine[line2] + 1,
|
|
40
|
+
line: line2 + 1
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const line = binarySearch(index, input);
|
|
44
|
+
return {
|
|
45
|
+
column: index - input[line] + 1,
|
|
46
|
+
line: line + 1
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { indexToLineColumn as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const isVisulimaError = (error) => error instanceof Error && error.type === "VisulimaError";
|
|
2
|
+
class VisulimaError extends Error {
|
|
3
|
+
loc;
|
|
4
|
+
title;
|
|
5
|
+
/**
|
|
6
|
+
* A message that explains to the user how they can fix the error.
|
|
7
|
+
*/
|
|
8
|
+
hint;
|
|
9
|
+
type = "VisulimaError";
|
|
10
|
+
constructor({ cause, hint, location, message, name, stack, title }) {
|
|
11
|
+
super(message, {
|
|
12
|
+
cause
|
|
13
|
+
});
|
|
14
|
+
this.title = title;
|
|
15
|
+
this.name = name;
|
|
16
|
+
this.stack = stack ?? this.stack;
|
|
17
|
+
this.loc = location;
|
|
18
|
+
this.hint = hint;
|
|
19
|
+
}
|
|
20
|
+
setLocation(location) {
|
|
21
|
+
this.loc = location;
|
|
22
|
+
}
|
|
23
|
+
setName(name) {
|
|
24
|
+
this.name = name;
|
|
25
|
+
}
|
|
26
|
+
setMessage(message) {
|
|
27
|
+
this.message = message;
|
|
28
|
+
}
|
|
29
|
+
setHint(hint) {
|
|
30
|
+
this.hint = hint;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { VisulimaError, isVisulimaError };
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
const debugLog = (message, ...arguments_) => {
|
|
2
|
+
if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
|
|
3
|
+
console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
const UNKNOWN_FUNCTION = "<unknown>";
|
|
7
|
+
const CHROMIUM_REGEX = /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
|
8
|
+
const CHROMIUM_EVAL_REGEX = /\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/;
|
|
9
|
+
const CHROMIUM_MAPPED = /(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/;
|
|
10
|
+
const WINDOWS_EVAL_REGEX = /(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/;
|
|
11
|
+
const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
|
|
12
|
+
const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
|
|
13
|
+
const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
|
|
14
|
+
const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
15
|
+
const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
16
|
+
const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
|
|
17
|
+
const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
|
|
18
|
+
const extractSafariExtensionDetails = (methodName, url) => {
|
|
19
|
+
const isSafariExtension = methodName.includes("safari-extension");
|
|
20
|
+
const isSafariWebExtension = methodName.includes("safari-web-extension");
|
|
21
|
+
return isSafariExtension || isSafariWebExtension ? [
|
|
22
|
+
methodName.includes("@") ? methodName.split("@")[0] : UNKNOWN_FUNCTION,
|
|
23
|
+
isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`
|
|
24
|
+
] : [methodName, url];
|
|
25
|
+
};
|
|
26
|
+
const parseMapped = (trace, maybeMapped) => {
|
|
27
|
+
const match = CHROMIUM_MAPPED.exec(maybeMapped);
|
|
28
|
+
if (match) {
|
|
29
|
+
trace.file = match[1];
|
|
30
|
+
trace.line = +match[2];
|
|
31
|
+
trace.column = +match[3];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const parseNode = (line) => {
|
|
35
|
+
const nestedNode = NODE_NESTED_REGEX.exec(line);
|
|
36
|
+
if (nestedNode) {
|
|
37
|
+
debugLog(`parse nested node error stack line: "${line}"`, `found: ${JSON.stringify(nestedNode)}`);
|
|
38
|
+
const split = nestedNode[2].split(":");
|
|
39
|
+
return {
|
|
40
|
+
column: split[2] ? +split[2] : void 0,
|
|
41
|
+
file: split[0],
|
|
42
|
+
line: split[1] ? +split[1] : void 0,
|
|
43
|
+
methodName: nestedNode[1] || UNKNOWN_FUNCTION,
|
|
44
|
+
raw: line,
|
|
45
|
+
type: void 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const node = NODE_REGEX.exec(line);
|
|
49
|
+
if (node) {
|
|
50
|
+
debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
|
|
51
|
+
const trace = {
|
|
52
|
+
column: node[4] ? +node[4] : void 0,
|
|
53
|
+
file: node[2] ? node[2].replace(/at\s/, "") : void 0,
|
|
54
|
+
line: node[3] ? +node[3] : void 0,
|
|
55
|
+
methodName: node[1] || UNKNOWN_FUNCTION,
|
|
56
|
+
raw: line,
|
|
57
|
+
type: line.startsWith("internal") ? "internal" : void 0
|
|
58
|
+
};
|
|
59
|
+
parseMapped(trace, `${node[2]}:${node[3]}:${node[4]}`);
|
|
60
|
+
return trace;
|
|
61
|
+
}
|
|
62
|
+
return void 0;
|
|
63
|
+
};
|
|
64
|
+
const parseChromium = (line) => {
|
|
65
|
+
const parts = CHROMIUM_REGEX.exec(line);
|
|
66
|
+
if (parts) {
|
|
67
|
+
debugLog(`parse chrome error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
|
|
68
|
+
const isNative = parts[2]?.startsWith("native");
|
|
69
|
+
const isEval = parts[2]?.startsWith("eval") || parts[1]?.startsWith("eval");
|
|
70
|
+
let evalOrigin;
|
|
71
|
+
let windowsParts;
|
|
72
|
+
if (isEval) {
|
|
73
|
+
const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
|
|
74
|
+
if (subMatch) {
|
|
75
|
+
const split = /^(\S+):(\d+):(\d+)$|^(\S+):(\d+)$/.exec(subMatch[1]);
|
|
76
|
+
if (split) {
|
|
77
|
+
parts[2] = split[4] ?? split[1];
|
|
78
|
+
parts[3] = split[5] ?? split[2];
|
|
79
|
+
parts[4] = split[3];
|
|
80
|
+
} else if (subMatch[2]) {
|
|
81
|
+
parts[2] = subMatch[1];
|
|
82
|
+
}
|
|
83
|
+
if (subMatch[2]) {
|
|
84
|
+
evalOrigin = {
|
|
85
|
+
column: subMatch[4] ? +subMatch[4] : void 0,
|
|
86
|
+
file: subMatch[2],
|
|
87
|
+
line: subMatch[3] ? +subMatch[3] : void 0,
|
|
88
|
+
methodName: "eval",
|
|
89
|
+
raw: line,
|
|
90
|
+
type: "eval"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
|
|
95
|
+
if (windowsSubMatch) {
|
|
96
|
+
windowsParts = {
|
|
97
|
+
column: windowsSubMatch[5] ? +windowsSubMatch[5] : void 0,
|
|
98
|
+
file: windowsSubMatch[3],
|
|
99
|
+
line: windowsSubMatch[4] ? +windowsSubMatch[4] : void 0
|
|
100
|
+
};
|
|
101
|
+
evalOrigin = {
|
|
102
|
+
column: windowsSubMatch[8] ? +windowsSubMatch[8] : void 0,
|
|
103
|
+
file: windowsSubMatch[2],
|
|
104
|
+
line: windowsSubMatch[7] ? +windowsSubMatch[7] : void 0,
|
|
105
|
+
methodName: "eval",
|
|
106
|
+
raw: windowsSubMatch[0],
|
|
107
|
+
type: "eval"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const [methodName, file] = extractSafariExtensionDetails(
|
|
113
|
+
// Normalize IE's 'Anonymous function'
|
|
114
|
+
parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
|
|
115
|
+
parts[2]
|
|
116
|
+
);
|
|
117
|
+
const trace = {
|
|
118
|
+
column: parts[4] ? +parts[4] : void 0,
|
|
119
|
+
evalOrigin,
|
|
120
|
+
file,
|
|
121
|
+
line: parts[3] ? +parts[3] : void 0,
|
|
122
|
+
methodName,
|
|
123
|
+
raw: line,
|
|
124
|
+
// eslint-disable-next-line sonarjs/no-nested-conditional
|
|
125
|
+
type: isEval ? "eval" : isNative ? "native" : void 0
|
|
126
|
+
};
|
|
127
|
+
if (windowsParts) {
|
|
128
|
+
trace.column = windowsParts.column;
|
|
129
|
+
trace.file = windowsParts.file;
|
|
130
|
+
trace.line = windowsParts.line;
|
|
131
|
+
} else {
|
|
132
|
+
parseMapped(trace, `${file}:${parts[3]}:${parts[4]}`);
|
|
133
|
+
}
|
|
134
|
+
return trace;
|
|
135
|
+
}
|
|
136
|
+
return void 0;
|
|
137
|
+
};
|
|
138
|
+
const parseGecko = (line, topFrameMeta) => {
|
|
139
|
+
const parts = GECKO_REGEX.exec(line);
|
|
140
|
+
if (parts) {
|
|
141
|
+
debugLog(`parse gecko error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
|
|
142
|
+
const isEval = parts[3]?.includes(" > eval");
|
|
143
|
+
const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);
|
|
144
|
+
let evalOrigin;
|
|
145
|
+
if (isEval && subMatch) {
|
|
146
|
+
parts[3] = subMatch[1];
|
|
147
|
+
evalOrigin = {
|
|
148
|
+
column: parts[5] ? +parts[5] : void 0,
|
|
149
|
+
file: parts[3],
|
|
150
|
+
line: parts[4] ? +parts[4] : void 0,
|
|
151
|
+
methodName: "eval",
|
|
152
|
+
raw: line,
|
|
153
|
+
type: "eval"
|
|
154
|
+
};
|
|
155
|
+
parts[4] = subMatch[2];
|
|
156
|
+
}
|
|
157
|
+
const [methodName, file] = extractSafariExtensionDetails(
|
|
158
|
+
// Normalize IE's 'Anonymous function'
|
|
159
|
+
parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
|
|
160
|
+
parts[3]
|
|
161
|
+
);
|
|
162
|
+
let column;
|
|
163
|
+
if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.column) {
|
|
164
|
+
column = topFrameMeta.column;
|
|
165
|
+
} else if (!isEval && parts[5]) {
|
|
166
|
+
column = +parts[5];
|
|
167
|
+
}
|
|
168
|
+
let lineNumber;
|
|
169
|
+
if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.line) {
|
|
170
|
+
lineNumber = topFrameMeta.line;
|
|
171
|
+
} else if (parts[4]) {
|
|
172
|
+
lineNumber = +parts[4];
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
column,
|
|
176
|
+
evalOrigin,
|
|
177
|
+
file,
|
|
178
|
+
line: lineNumber,
|
|
179
|
+
methodName,
|
|
180
|
+
raw: line,
|
|
181
|
+
// eslint-disable-next-line sonarjs/no-nested-conditional
|
|
182
|
+
type: isEval ? "eval" : file.includes("[native code]") ? "native" : void 0
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return void 0;
|
|
186
|
+
};
|
|
187
|
+
const parseFirefox = (line, topFrameMeta) => {
|
|
188
|
+
const parts = FIREFOX_REGEX.exec(line);
|
|
189
|
+
const isEval = parts ? parts[2].includes(" > eval") : false;
|
|
190
|
+
if (!isEval && parts) {
|
|
191
|
+
debugLog(`parse firefox error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
|
|
192
|
+
return {
|
|
193
|
+
column: parts[4] ? +parts[4] : topFrameMeta?.column ?? void 0,
|
|
194
|
+
file: parts[2],
|
|
195
|
+
line: parts[3] ? +parts[3] : topFrameMeta?.line ?? void 0,
|
|
196
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
197
|
+
raw: line,
|
|
198
|
+
type: void 0
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return void 0;
|
|
202
|
+
};
|
|
203
|
+
const parseReactAndroidNative = (line) => {
|
|
204
|
+
const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);
|
|
205
|
+
if (parts) {
|
|
206
|
+
debugLog(`parse react android native error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
|
|
207
|
+
return {
|
|
208
|
+
column: parts[3] ? +parts[3] : void 0,
|
|
209
|
+
file: parts[1],
|
|
210
|
+
line: parts[2] ? +parts[2] : void 0,
|
|
211
|
+
methodName: UNKNOWN_FUNCTION,
|
|
212
|
+
raw: line,
|
|
213
|
+
type: void 0
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return void 0;
|
|
217
|
+
};
|
|
218
|
+
const parseStacktrace = (error, { filter, frameLimit = 50 } = {}) => {
|
|
219
|
+
let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
|
|
220
|
+
const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, "$1") : line;
|
|
221
|
+
return cleanedLine.replace(/^\s+|\s+$/g, "");
|
|
222
|
+
}).filter((line) => !/\S*(?:Error: |AggregateError:)/.test(line) && line !== "eval code");
|
|
223
|
+
if (filter) {
|
|
224
|
+
lines = lines.filter((element) => filter(element));
|
|
225
|
+
}
|
|
226
|
+
lines = lines.slice(0, frameLimit);
|
|
227
|
+
return lines.reduce((stack, line, currentIndex) => {
|
|
228
|
+
if (!line) {
|
|
229
|
+
return stack;
|
|
230
|
+
}
|
|
231
|
+
if (line.length > 1024) {
|
|
232
|
+
return stack;
|
|
233
|
+
}
|
|
234
|
+
let parseResult;
|
|
235
|
+
if (/^\s*in\s.*/.test(line)) {
|
|
236
|
+
parseResult = parseNode(line);
|
|
237
|
+
} else if (/^.*?\s*at\s.*/.test(line)) {
|
|
238
|
+
parseResult = parseChromium(line);
|
|
239
|
+
} else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
|
|
240
|
+
let topFrameMeta;
|
|
241
|
+
if (currentIndex === 0) {
|
|
242
|
+
if (error.columnNumber || error.lineNumber) {
|
|
243
|
+
topFrameMeta = {
|
|
244
|
+
// @ts-expect-error columnNumber and columnNumber property only exists on Firefox
|
|
245
|
+
column: error.columnNumber,
|
|
246
|
+
// @ts-expect-error columnNumber and lineNumber property only exists on Firefox
|
|
247
|
+
line: error.lineNumber,
|
|
248
|
+
type: "firefox"
|
|
249
|
+
};
|
|
250
|
+
} else if (error.line || error.column) {
|
|
251
|
+
topFrameMeta = {
|
|
252
|
+
// @ts-expect-error column property only exists on safari
|
|
253
|
+
column: error.column,
|
|
254
|
+
// @ts-expect-error line property only exists on safari
|
|
255
|
+
line: error.line,
|
|
256
|
+
type: "safari"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
parseResult = parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
|
|
261
|
+
} else {
|
|
262
|
+
parseResult = parseReactAndroidNative(line);
|
|
263
|
+
}
|
|
264
|
+
if (parseResult) {
|
|
265
|
+
stack.push(parseResult);
|
|
266
|
+
} else {
|
|
267
|
+
debugLog(`parse error stack line: "${line}"`, "not parser found");
|
|
268
|
+
}
|
|
269
|
+
return stack;
|
|
270
|
+
}, []);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export { parseStacktrace as default };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
existsSync,
|
|
22
|
+
readFileSync
|
|
23
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
24
|
+
const {
|
|
25
|
+
relative
|
|
26
|
+
} = __cjs_getBuiltinModule("node:path");
|
|
27
|
+
const {
|
|
28
|
+
cwd
|
|
29
|
+
} = __cjs_getProcess;
|
|
30
|
+
const {
|
|
31
|
+
fileURLToPath
|
|
32
|
+
} = __cjs_getBuiltinModule("node:url");
|
|
33
|
+
import { codeFrame } from '../code-frame/index.js';
|
|
34
|
+
import parseStacktrace from './parseStacktrace-oQvk7wYp.js';
|
|
35
|
+
|
|
36
|
+
const getPrefix = (prefix, indentation, deep) => {
|
|
37
|
+
if (deep === 0) {
|
|
38
|
+
return prefix.toString();
|
|
39
|
+
}
|
|
40
|
+
if (indentation === " ") {
|
|
41
|
+
return prefix + " ".repeat(deep);
|
|
42
|
+
}
|
|
43
|
+
return prefix + " ".repeat(indentation * deep);
|
|
44
|
+
};
|
|
45
|
+
const getRelativePath = (filePath, cwdPath) => {
|
|
46
|
+
const path = filePath.replace("async file:", "file:");
|
|
47
|
+
return relative(cwdPath, path.startsWith("file:") ? fileURLToPath(path) : path);
|
|
48
|
+
};
|
|
49
|
+
const getTitleText = (error, hideErrorTitle, color) => {
|
|
50
|
+
if (hideErrorTitle) {
|
|
51
|
+
return color.title(error.message);
|
|
52
|
+
}
|
|
53
|
+
const messagePart = error.message ? `: ${error.message}` : "";
|
|
54
|
+
return color.title(error.name + messagePart);
|
|
55
|
+
};
|
|
56
|
+
const getMessage = (error, { color, hideErrorTitle, indentation, prefix }, deep) => `${getPrefix(prefix, indentation, deep)}${getTitleText(error, hideErrorTitle, color)}
|
|
57
|
+
`;
|
|
58
|
+
const getHint = (error, { color, indentation, prefix }, deep) => {
|
|
59
|
+
if (error.hint === void 0) {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
const spaces = getPrefix(prefix, indentation, deep);
|
|
63
|
+
let message = "";
|
|
64
|
+
if (Array.isArray(error.hint)) {
|
|
65
|
+
for (const line of error.hint) {
|
|
66
|
+
message += `${(spaces + line).toString()}
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
message += spaces + error.hint;
|
|
71
|
+
}
|
|
72
|
+
return color.hint(message);
|
|
73
|
+
};
|
|
74
|
+
const getMainFrame = (trace, { color, cwd: cwdPath, displayShortPath, indentation, prefix }, deep = 0) => {
|
|
75
|
+
const filePath = displayShortPath ? getRelativePath(trace.file, cwdPath) : trace.file;
|
|
76
|
+
const { fileLine, method } = color;
|
|
77
|
+
return `${getPrefix(prefix, indentation, deep)}at ${trace.methodName ? `${method(trace.methodName)} ` : ""}${fileLine(filePath)}:${fileLine(
|
|
78
|
+
trace.line?.toString() ?? ""
|
|
79
|
+
)}`.toString();
|
|
80
|
+
};
|
|
81
|
+
const getCode = (trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
|
|
82
|
+
if (trace.file === void 0) {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
const filePath = trace.file.replace("file://", "");
|
|
86
|
+
if (!existsSync(filePath)) {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
const fileContent = readFileSync(filePath, "utf8");
|
|
90
|
+
return codeFrame(
|
|
91
|
+
fileContent,
|
|
92
|
+
{
|
|
93
|
+
start: { column: trace.column, line: trace.line }
|
|
94
|
+
},
|
|
95
|
+
{ color, linesAbove, linesBelow, prefix: getPrefix(prefix, indentation, deep), showGutter, showLineNumbers, tabWidth }
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
const getErrors = (error, options, deep) => {
|
|
99
|
+
if (error.errors.length === 0) {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
let message = `${getPrefix(options.prefix, options.indentation, deep)}Errors:
|
|
103
|
+
|
|
104
|
+
`;
|
|
105
|
+
let first = true;
|
|
106
|
+
for (const error_ of error.errors) {
|
|
107
|
+
if (first) {
|
|
108
|
+
first = false;
|
|
109
|
+
} else {
|
|
110
|
+
message += "\n\n";
|
|
111
|
+
}
|
|
112
|
+
message += internalRenderError(error_, { ...options, framesMaxLimit: 1, hideErrorCodeView: options.hideErrorErrorsCodeView }, deep + 1);
|
|
113
|
+
}
|
|
114
|
+
return `
|
|
115
|
+
${message}`;
|
|
116
|
+
};
|
|
117
|
+
const getCause = (error, options, deep) => {
|
|
118
|
+
let message = `${getPrefix(options.prefix, options.indentation, deep)}Caused by:
|
|
119
|
+
|
|
120
|
+
`;
|
|
121
|
+
const cause = error.cause;
|
|
122
|
+
message += getMessage(cause, options, deep);
|
|
123
|
+
const stacktrace = parseStacktrace(cause);
|
|
124
|
+
const mainFrame = stacktrace.shift();
|
|
125
|
+
const hint = getHint(cause, options, deep);
|
|
126
|
+
if (hint) {
|
|
127
|
+
message += `${hint}
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
if (mainFrame) {
|
|
131
|
+
message += getMainFrame(mainFrame, options, deep);
|
|
132
|
+
if (!options.hideErrorCauseCodeView) {
|
|
133
|
+
const code = getCode(mainFrame, options, deep);
|
|
134
|
+
if (code !== void 0) {
|
|
135
|
+
message += `
|
|
136
|
+
${code}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (cause.cause) {
|
|
141
|
+
message += `
|
|
142
|
+
${getCause(cause, options, deep + 1)}`;
|
|
143
|
+
} else if (cause instanceof AggregateError) {
|
|
144
|
+
const errors = getErrors(cause, options, deep);
|
|
145
|
+
if (errors !== void 0) {
|
|
146
|
+
message += `
|
|
147
|
+
${errors}`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return `
|
|
151
|
+
${message}`;
|
|
152
|
+
};
|
|
153
|
+
const getStacktrace = (stack, options) => (stack.length > 0 ? "\n" : "") + stack.map((frame) => getMainFrame(frame, options)).join("\n");
|
|
154
|
+
const internalRenderError = (error, options, deep) => {
|
|
155
|
+
const config = {
|
|
156
|
+
cwd: cwd(),
|
|
157
|
+
displayShortPath: false,
|
|
158
|
+
filterStacktrace: void 0,
|
|
159
|
+
framesMaxLimit: Number.POSITIVE_INFINITY,
|
|
160
|
+
hideErrorCauseCodeView: false,
|
|
161
|
+
hideErrorCodeView: false,
|
|
162
|
+
hideErrorErrorsCodeView: false,
|
|
163
|
+
hideErrorTitle: false,
|
|
164
|
+
hideMessage: false,
|
|
165
|
+
indentation: 4,
|
|
166
|
+
linesAbove: 2,
|
|
167
|
+
linesBelow: 3,
|
|
168
|
+
prefix: "",
|
|
169
|
+
showGutter: true,
|
|
170
|
+
showLineNumbers: true,
|
|
171
|
+
tabWidth: 4,
|
|
172
|
+
...options,
|
|
173
|
+
color: {
|
|
174
|
+
fileLine: (value) => value,
|
|
175
|
+
gutter: (value) => value,
|
|
176
|
+
hint: (value) => value,
|
|
177
|
+
marker: (value) => value,
|
|
178
|
+
message: (value) => value,
|
|
179
|
+
method: (value) => value,
|
|
180
|
+
title: (value) => value,
|
|
181
|
+
...options.color
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const stack = parseStacktrace(error, {
|
|
185
|
+
filter: options.filterStacktrace,
|
|
186
|
+
frameLimit: config.framesMaxLimit
|
|
187
|
+
});
|
|
188
|
+
const mainFrame = stack.shift();
|
|
189
|
+
return [
|
|
190
|
+
options.hideMessage ? void 0 : getMessage(error, config, deep),
|
|
191
|
+
getHint(error, config, deep),
|
|
192
|
+
mainFrame ? getMainFrame(mainFrame, config, deep) : void 0,
|
|
193
|
+
mainFrame && !config.hideErrorCodeView ? getCode(mainFrame, config, deep) : void 0,
|
|
194
|
+
error instanceof AggregateError ? getErrors(error, config, deep) : void 0,
|
|
195
|
+
error.cause === void 0 ? void 0 : getCause(error, config, deep),
|
|
196
|
+
stack.length > 0 ? getStacktrace(stack, config) : void 0
|
|
197
|
+
].filter(Boolean).join("\n").replaceAll("\\", "/");
|
|
198
|
+
};
|
|
199
|
+
const renderError = (error, options = {}) => {
|
|
200
|
+
if (options.framesMaxLimit !== void 0 && options.framesMaxLimit <= 0) {
|
|
201
|
+
throw new RangeError("The 'framesMaxLimit' option must be a positive number");
|
|
202
|
+
}
|
|
203
|
+
return internalRenderError(error, options, 0);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export { renderError };
|