@visulima/error 4.5.0 → 4.6.1

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.
Files changed (85) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +148 -4
  3. package/dist/code-frame/index.cjs +6 -135
  4. package/dist/code-frame/index.mjs +6 -130
  5. package/dist/error/index.cjs +1 -18
  6. package/dist/error/index.d.cts +19 -1
  7. package/dist/error/index.d.mts +19 -1
  8. package/dist/error/index.d.ts +19 -1
  9. package/dist/error/index.mjs +1 -5
  10. package/dist/index.cjs +1 -36
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.mjs +1 -13
  15. package/dist/packem_shared/NonError-CQn4sdxd.cjs +1 -0
  16. package/dist/packem_shared/NonError-CS10kwil.mjs +1 -0
  17. package/dist/packem_shared/addKnownErrorConstructor-B5dNFGsR.cjs +1 -0
  18. package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.mjs +1 -0
  19. package/dist/packem_shared/aiFinder-Be-xHFVO.mjs +1 -0
  20. package/dist/packem_shared/aiFinder-CN0pneE2.cjs +1 -0
  21. package/dist/packem_shared/aiSolutionResponse-C5apAmTu.cjs +10 -0
  22. package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.mjs +10 -0
  23. package/dist/packem_shared/captureRawStackTrace-B9d1821F.cjs +1 -0
  24. package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.mjs +1 -0
  25. package/dist/packem_shared/deserializeError-2C6o7QF7.cjs +1 -0
  26. package/dist/packem_shared/deserializeError-tzZhIV70.mjs +1 -0
  27. package/dist/packem_shared/errorHintFinder-C_g0nvml.mjs +2 -0
  28. package/dist/packem_shared/errorHintFinder-DRCn1Ysx.cjs +2 -0
  29. package/dist/packem_shared/formatStackFrameLine-DD2DUdW0.cjs +2 -0
  30. package/dist/packem_shared/formatStackFrameLine-iU54KA81.mjs +2 -0
  31. package/dist/packem_shared/getErrorCauses-B7_Z_gEF.cjs +1 -0
  32. package/dist/packem_shared/getErrorCauses-D025FGyO.mjs +1 -0
  33. package/dist/packem_shared/index-CLFYRLyq.mjs +1 -0
  34. package/dist/packem_shared/index-CqSGigts.cjs +1 -0
  35. package/dist/packem_shared/indexToLineColumn-B1F7aNZh.mjs +1 -0
  36. package/dist/packem_shared/indexToLineColumn-C_v57REF.cjs +1 -0
  37. package/dist/packem_shared/isVisulimaError-CrvBm0kw.cjs +1 -0
  38. package/dist/packem_shared/isVisulimaError-jVZgumOU.mjs +1 -0
  39. package/dist/packem_shared/parseStacktrace-Dnxnc4PL.mjs +2 -0
  40. package/dist/packem_shared/parseStacktrace-MW4-SLXl.cjs +2 -0
  41. package/dist/packem_shared/renderError-D7R71d_7.mjs +18 -0
  42. package/dist/packem_shared/renderError-D8XJnkIF.cjs +18 -0
  43. package/dist/packem_shared/ruleBasedFinder-DTyLJeCs.cjs +35 -0
  44. package/dist/packem_shared/ruleBasedFinder-W5UXhtHl.mjs +35 -0
  45. package/dist/packem_shared/serializeError-7S1IG6zs.cjs +1 -0
  46. package/dist/packem_shared/serializeError-Bc-QciX0.mjs +1 -0
  47. package/dist/solution/ai/ai-prompt.cjs +7 -17
  48. package/dist/solution/ai/ai-prompt.mjs +7 -15
  49. package/dist/solution/ai/index.cjs +1 -13
  50. package/dist/solution/ai/index.d.cts +2 -2
  51. package/dist/solution/ai/index.d.mts +2 -2
  52. package/dist/solution/ai/index.d.ts +2 -2
  53. package/dist/solution/ai/index.mjs +1 -3
  54. package/dist/solution/index.cjs +1 -11
  55. package/dist/solution/index.mjs +1 -2
  56. package/dist/stacktrace/index.cjs +1 -12
  57. package/dist/stacktrace/index.d.cts +2 -2
  58. package/dist/stacktrace/index.d.mts +2 -2
  59. package/dist/stacktrace/index.d.ts +2 -2
  60. package/dist/stacktrace/index.mjs +1 -2
  61. package/package.json +1 -1
  62. package/dist/packem_shared/aiFinder-BGfwKKxE.cjs +0 -263
  63. package/dist/packem_shared/aiFinder-Bk1vt0_x.mjs +0 -261
  64. package/dist/packem_shared/aiSolutionResponse-BPckbL56.cjs +0 -37
  65. package/dist/packem_shared/aiSolutionResponse-bDi4ad8f.mjs +0 -35
  66. package/dist/packem_shared/captureRawStackTrace-ClSI1tHb.cjs +0 -14
  67. package/dist/packem_shared/captureRawStackTrace-Tl3Rqkat.mjs +0 -12
  68. package/dist/packem_shared/errorHintFinder-CQy_qIK3.mjs +0 -23
  69. package/dist/packem_shared/errorHintFinder-DZugFHq0.cjs +0 -25
  70. package/dist/packem_shared/formatStackFrameLine-DcXSX--m.cjs +0 -31
  71. package/dist/packem_shared/formatStackFrameLine-DqkmKWH3.mjs +0 -26
  72. package/dist/packem_shared/getErrorCauses-CG_JRE6j.mjs +0 -24
  73. package/dist/packem_shared/getErrorCauses-miTeYJEG.cjs +0 -26
  74. package/dist/packem_shared/indexToLineColumn-DjmjeiIY.cjs +0 -56
  75. package/dist/packem_shared/indexToLineColumn-Dx91YDU1.mjs +0 -54
  76. package/dist/packem_shared/isVisulimaError-BVLWvREw.cjs +0 -45
  77. package/dist/packem_shared/isVisulimaError-H6TqEA42.mjs +0 -40
  78. package/dist/packem_shared/parseStacktrace-6pFoXW43.cjs +0 -282
  79. package/dist/packem_shared/parseStacktrace-BKGoWCwC.mjs +0 -280
  80. package/dist/packem_shared/renderError-BWpM2m6k.mjs +0 -165
  81. package/dist/packem_shared/renderError-CXZTAXig.cjs +0 -169
  82. package/dist/packem_shared/ruleBasedFinder-BYrndubA.mjs +0 -227
  83. package/dist/packem_shared/ruleBasedFinder-y_-5kbeT.cjs +0 -229
  84. package/dist/packem_shared/serializeError-CT7s0Ffk.cjs +0 -157
  85. package/dist/packem_shared/serializeError-DusTUACt.mjs +0 -153
@@ -1,282 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- const debugLog = /* @__PURE__ */ __name((message, ...arguments_) => {
6
- if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
7
- console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
8
- }
9
- }, "debugLog");
10
- const UNKNOWN_FUNCTION = "<unknown>";
11
- const CHROMIUM_REGEX = (
12
- // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking
13
- /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i
14
- );
15
- const CHROMIUM_EVAL_REGEX = /\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/;
16
- const CHROMIUM_MAPPED = /(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/;
17
- const WINDOWS_EVAL_REGEX = /(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/;
18
- const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
19
- const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
20
- const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
21
- const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
22
- const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
23
- const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
24
- const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
25
- const extractSafariExtensionDetails = /* @__PURE__ */ __name((methodName, url) => {
26
- const isSafariExtension = methodName.includes("safari-extension");
27
- const isSafariWebExtension = methodName.includes("safari-web-extension");
28
- return isSafariExtension || isSafariWebExtension ? [
29
- methodName.includes("@") ? methodName.split("@")[0] : UNKNOWN_FUNCTION,
30
- isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`
31
- ] : [methodName, url];
32
- }, "extractSafariExtensionDetails");
33
- const parseMapped = /* @__PURE__ */ __name((trace, maybeMapped) => {
34
- const match = CHROMIUM_MAPPED.exec(maybeMapped);
35
- if (match) {
36
- trace.file = match[1];
37
- trace.line = +match[2];
38
- trace.column = +match[3];
39
- }
40
- }, "parseMapped");
41
- const parseNode = /* @__PURE__ */ __name((line) => {
42
- const nestedNode = NODE_NESTED_REGEX.exec(line);
43
- if (nestedNode) {
44
- debugLog(`parse nested node error stack line: "${line}"`, `found: ${JSON.stringify(nestedNode)}`);
45
- const split = nestedNode[2].split(":");
46
- return {
47
- column: split[2] ? +split[2] : void 0,
48
- file: split[0],
49
- line: split[1] ? +split[1] : void 0,
50
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
51
- methodName: nestedNode[1] || UNKNOWN_FUNCTION,
52
- raw: line,
53
- type: void 0
54
- };
55
- }
56
- const node = NODE_REGEX.exec(line);
57
- if (node) {
58
- debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
59
- const trace = {
60
- column: node[4] ? +node[4] : void 0,
61
- file: node[2] ? node[2].replace(/at\s/, "") : void 0,
62
- line: node[3] ? +node[3] : void 0,
63
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
64
- methodName: node[1] || UNKNOWN_FUNCTION,
65
- raw: line,
66
- type: line.startsWith("internal") ? "internal" : void 0
67
- };
68
- parseMapped(trace, node[2] + ":" + node[3] + ":" + node[4]);
69
- return trace;
70
- }
71
- return void 0;
72
- }, "parseNode");
73
- const parseChromium = /* @__PURE__ */ __name((line) => {
74
- const parts = CHROMIUM_REGEX.exec(line);
75
- if (parts) {
76
- debugLog(`parse chrome error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
77
- const isNative = parts[2]?.startsWith("native");
78
- const isEval = parts[2]?.startsWith("eval") || parts[1]?.startsWith("eval");
79
- let evalOrigin;
80
- let windowsParts;
81
- if (isEval) {
82
- const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
83
- if (subMatch) {
84
- const split = /(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(subMatch[1]);
85
- if (split) {
86
- parts[2] = split[4] ?? split[1];
87
- parts[3] = split[5] ?? split[2];
88
- parts[4] = split[3];
89
- } else if (subMatch[2]) {
90
- parts[2] = subMatch[1];
91
- }
92
- if (subMatch[2]) {
93
- evalOrigin = {
94
- column: subMatch[4] ? +subMatch[4] : void 0,
95
- file: subMatch[2],
96
- line: subMatch[3] ? +subMatch[3] : void 0,
97
- methodName: "eval",
98
- raw: line,
99
- type: "eval"
100
- };
101
- }
102
- } else {
103
- const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
104
- if (windowsSubMatch) {
105
- windowsParts = {
106
- column: windowsSubMatch[5] ? +windowsSubMatch[5] : void 0,
107
- file: windowsSubMatch[3],
108
- line: windowsSubMatch[4] ? +windowsSubMatch[4] : void 0
109
- };
110
- evalOrigin = {
111
- column: windowsSubMatch[8] ? +windowsSubMatch[8] : void 0,
112
- file: windowsSubMatch[2],
113
- line: windowsSubMatch[7] ? +windowsSubMatch[7] : void 0,
114
- methodName: "eval",
115
- raw: windowsSubMatch[0],
116
- type: "eval"
117
- };
118
- }
119
- }
120
- }
121
- const [methodName, file] = extractSafariExtensionDetails(
122
- // Normalize IE's 'Anonymous function'
123
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
124
- parts[2]
125
- );
126
- const trace = {
127
- column: parts[4] ? +parts[4] : void 0,
128
- evalOrigin,
129
- file,
130
- line: parts[3] ? +parts[3] : void 0,
131
- methodName,
132
- raw: line,
133
- type: isEval ? "eval" : isNative ? "native" : void 0
134
- };
135
- if (windowsParts) {
136
- trace.column = windowsParts.column;
137
- trace.file = windowsParts.file;
138
- trace.line = windowsParts.line;
139
- } else {
140
- parseMapped(trace, file + ":" + parts[3] + ":" + parts[4]);
141
- }
142
- return trace;
143
- }
144
- return void 0;
145
- }, "parseChromium");
146
- const parseGecko = /* @__PURE__ */ __name((line, topFrameMeta) => {
147
- const parts = GECKO_REGEX.exec(line);
148
- if (parts) {
149
- debugLog(`parse gecko error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
150
- const isEval = parts[3]?.includes(" > eval");
151
- const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);
152
- let evalOrigin;
153
- if (isEval && subMatch) {
154
- parts[3] = subMatch[1];
155
- evalOrigin = {
156
- column: parts[5] ? +parts[5] : void 0,
157
- file: parts[3],
158
- line: parts[4] ? +parts[4] : void 0,
159
- methodName: "eval",
160
- raw: line,
161
- type: "eval"
162
- };
163
- parts[4] = subMatch[2];
164
- }
165
- const [methodName, file] = extractSafariExtensionDetails(
166
- // Normalize IE's 'Anonymous function'
167
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
168
- parts[3]
169
- );
170
- let column;
171
- if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.column) {
172
- column = topFrameMeta.column;
173
- } else if (!isEval && parts[5]) {
174
- column = +parts[5];
175
- }
176
- let lineNumber;
177
- if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.line) {
178
- lineNumber = topFrameMeta.line;
179
- } else if (parts[4]) {
180
- lineNumber = +parts[4];
181
- }
182
- return {
183
- column,
184
- evalOrigin,
185
- file,
186
- line: lineNumber,
187
- methodName,
188
- raw: line,
189
- type: isEval ? "eval" : file.includes("[native code]") ? "native" : void 0
190
- };
191
- }
192
- return void 0;
193
- }, "parseGecko");
194
- const parseFirefox = /* @__PURE__ */ __name((line, topFrameMeta) => {
195
- const parts = FIREFOX_REGEX.exec(line);
196
- const isEval = parts ? parts[2].includes(" > eval") : false;
197
- if (!isEval && parts) {
198
- debugLog(`parse firefox error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
199
- return {
200
- column: parts[4] ? +parts[4] : topFrameMeta?.column ?? void 0,
201
- file: parts[2],
202
- line: parts[3] ? +parts[3] : topFrameMeta?.line ?? void 0,
203
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
204
- methodName: parts[1] || UNKNOWN_FUNCTION,
205
- raw: line,
206
- type: void 0
207
- };
208
- }
209
- return void 0;
210
- }, "parseFirefox");
211
- const parseReactAndroidNative = /* @__PURE__ */ __name((line) => {
212
- const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);
213
- if (parts) {
214
- debugLog(`parse react android native error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
215
- return {
216
- column: parts[3] ? +parts[3] : void 0,
217
- file: parts[1],
218
- line: parts[2] ? +parts[2] : void 0,
219
- methodName: UNKNOWN_FUNCTION,
220
- raw: line,
221
- type: void 0
222
- };
223
- }
224
- return void 0;
225
- }, "parseReactAndroidNative");
226
- const parse = /* @__PURE__ */ __name((error, { filter, frameLimit = 50 } = {}) => {
227
- let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
228
- const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, "$1") : line;
229
- return cleanedLine.replace(/^\s+|\s+$/g, "");
230
- }).filter((line) => !/\S*(?:Error: |AggregateError:)/.test(line) && line !== "eval code");
231
- if (filter) {
232
- lines = lines.filter((element) => filter(element));
233
- }
234
- lines = lines.slice(0, frameLimit);
235
- return lines.reduce((stack, line, currentIndex) => {
236
- if (!line) {
237
- return stack;
238
- }
239
- if (line.length > 1024) {
240
- return stack;
241
- }
242
- let parseResult;
243
- if (/^\s*in\s.*/.test(line)) {
244
- parseResult = parseNode(line);
245
- } else if (/^.*?\s*at\s.*/.test(line)) {
246
- parseResult = parseChromium(line);
247
- } else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
248
- let topFrameMeta;
249
- if (currentIndex === 0) {
250
- if (error.columnNumber || error.lineNumber) {
251
- topFrameMeta = {
252
- // @ts-expect-error columnNumber and columnNumber property only exists on Firefox
253
- column: error.columnNumber,
254
- // @ts-expect-error columnNumber and lineNumber property only exists on Firefox
255
- line: error.lineNumber,
256
- type: "firefox"
257
- };
258
- } else if (error.line || error.column) {
259
- topFrameMeta = {
260
- // @ts-expect-error column property only exists on safari
261
- column: error.column,
262
- // @ts-expect-error line property only exists on safari
263
- line: error.line,
264
- type: "safari"
265
- };
266
- }
267
- }
268
- parseResult = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
269
- parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
270
- } else {
271
- parseResult = parseReactAndroidNative(line);
272
- }
273
- if (parseResult) {
274
- stack.push(parseResult);
275
- } else {
276
- debugLog(`parse error stack line: "${line}"`, "not parser found");
277
- }
278
- return stack;
279
- }, []);
280
- }, "parse");
281
-
282
- module.exports = parse;
@@ -1,280 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- const debugLog = /* @__PURE__ */ __name((message, ...arguments_) => {
4
- if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
5
- console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
6
- }
7
- }, "debugLog");
8
- const UNKNOWN_FUNCTION = "<unknown>";
9
- const CHROMIUM_REGEX = (
10
- // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking
11
- /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i
12
- );
13
- const CHROMIUM_EVAL_REGEX = /\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/;
14
- const CHROMIUM_MAPPED = /(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/;
15
- const WINDOWS_EVAL_REGEX = /(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/;
16
- const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
17
- const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
18
- const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
19
- const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
20
- const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
21
- const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
22
- const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
23
- const extractSafariExtensionDetails = /* @__PURE__ */ __name((methodName, url) => {
24
- const isSafariExtension = methodName.includes("safari-extension");
25
- const isSafariWebExtension = methodName.includes("safari-web-extension");
26
- return isSafariExtension || isSafariWebExtension ? [
27
- methodName.includes("@") ? methodName.split("@")[0] : UNKNOWN_FUNCTION,
28
- isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`
29
- ] : [methodName, url];
30
- }, "extractSafariExtensionDetails");
31
- const parseMapped = /* @__PURE__ */ __name((trace, maybeMapped) => {
32
- const match = CHROMIUM_MAPPED.exec(maybeMapped);
33
- if (match) {
34
- trace.file = match[1];
35
- trace.line = +match[2];
36
- trace.column = +match[3];
37
- }
38
- }, "parseMapped");
39
- const parseNode = /* @__PURE__ */ __name((line) => {
40
- const nestedNode = NODE_NESTED_REGEX.exec(line);
41
- if (nestedNode) {
42
- debugLog(`parse nested node error stack line: "${line}"`, `found: ${JSON.stringify(nestedNode)}`);
43
- const split = nestedNode[2].split(":");
44
- return {
45
- column: split[2] ? +split[2] : void 0,
46
- file: split[0],
47
- line: split[1] ? +split[1] : void 0,
48
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
49
- methodName: nestedNode[1] || UNKNOWN_FUNCTION,
50
- raw: line,
51
- type: void 0
52
- };
53
- }
54
- const node = NODE_REGEX.exec(line);
55
- if (node) {
56
- debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
57
- const trace = {
58
- column: node[4] ? +node[4] : void 0,
59
- file: node[2] ? node[2].replace(/at\s/, "") : void 0,
60
- line: node[3] ? +node[3] : void 0,
61
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
62
- methodName: node[1] || UNKNOWN_FUNCTION,
63
- raw: line,
64
- type: line.startsWith("internal") ? "internal" : void 0
65
- };
66
- parseMapped(trace, node[2] + ":" + node[3] + ":" + node[4]);
67
- return trace;
68
- }
69
- return void 0;
70
- }, "parseNode");
71
- const parseChromium = /* @__PURE__ */ __name((line) => {
72
- const parts = CHROMIUM_REGEX.exec(line);
73
- if (parts) {
74
- debugLog(`parse chrome error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
75
- const isNative = parts[2]?.startsWith("native");
76
- const isEval = parts[2]?.startsWith("eval") || parts[1]?.startsWith("eval");
77
- let evalOrigin;
78
- let windowsParts;
79
- if (isEval) {
80
- const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
81
- if (subMatch) {
82
- const split = /(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(subMatch[1]);
83
- if (split) {
84
- parts[2] = split[4] ?? split[1];
85
- parts[3] = split[5] ?? split[2];
86
- parts[4] = split[3];
87
- } else if (subMatch[2]) {
88
- parts[2] = subMatch[1];
89
- }
90
- if (subMatch[2]) {
91
- evalOrigin = {
92
- column: subMatch[4] ? +subMatch[4] : void 0,
93
- file: subMatch[2],
94
- line: subMatch[3] ? +subMatch[3] : void 0,
95
- methodName: "eval",
96
- raw: line,
97
- type: "eval"
98
- };
99
- }
100
- } else {
101
- const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
102
- if (windowsSubMatch) {
103
- windowsParts = {
104
- column: windowsSubMatch[5] ? +windowsSubMatch[5] : void 0,
105
- file: windowsSubMatch[3],
106
- line: windowsSubMatch[4] ? +windowsSubMatch[4] : void 0
107
- };
108
- evalOrigin = {
109
- column: windowsSubMatch[8] ? +windowsSubMatch[8] : void 0,
110
- file: windowsSubMatch[2],
111
- line: windowsSubMatch[7] ? +windowsSubMatch[7] : void 0,
112
- methodName: "eval",
113
- raw: windowsSubMatch[0],
114
- type: "eval"
115
- };
116
- }
117
- }
118
- }
119
- const [methodName, file] = extractSafariExtensionDetails(
120
- // Normalize IE's 'Anonymous function'
121
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
122
- parts[2]
123
- );
124
- const trace = {
125
- column: parts[4] ? +parts[4] : void 0,
126
- evalOrigin,
127
- file,
128
- line: parts[3] ? +parts[3] : void 0,
129
- methodName,
130
- raw: line,
131
- type: isEval ? "eval" : isNative ? "native" : void 0
132
- };
133
- if (windowsParts) {
134
- trace.column = windowsParts.column;
135
- trace.file = windowsParts.file;
136
- trace.line = windowsParts.line;
137
- } else {
138
- parseMapped(trace, file + ":" + parts[3] + ":" + parts[4]);
139
- }
140
- return trace;
141
- }
142
- return void 0;
143
- }, "parseChromium");
144
- const parseGecko = /* @__PURE__ */ __name((line, topFrameMeta) => {
145
- const parts = GECKO_REGEX.exec(line);
146
- if (parts) {
147
- debugLog(`parse gecko error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
148
- const isEval = parts[3]?.includes(" > eval");
149
- const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);
150
- let evalOrigin;
151
- if (isEval && subMatch) {
152
- parts[3] = subMatch[1];
153
- evalOrigin = {
154
- column: parts[5] ? +parts[5] : void 0,
155
- file: parts[3],
156
- line: parts[4] ? +parts[4] : void 0,
157
- methodName: "eval",
158
- raw: line,
159
- type: "eval"
160
- };
161
- parts[4] = subMatch[2];
162
- }
163
- const [methodName, file] = extractSafariExtensionDetails(
164
- // Normalize IE's 'Anonymous function'
165
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
166
- parts[3]
167
- );
168
- let column;
169
- if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.column) {
170
- column = topFrameMeta.column;
171
- } else if (!isEval && parts[5]) {
172
- column = +parts[5];
173
- }
174
- let lineNumber;
175
- if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.line) {
176
- lineNumber = topFrameMeta.line;
177
- } else if (parts[4]) {
178
- lineNumber = +parts[4];
179
- }
180
- return {
181
- column,
182
- evalOrigin,
183
- file,
184
- line: lineNumber,
185
- methodName,
186
- raw: line,
187
- type: isEval ? "eval" : file.includes("[native code]") ? "native" : void 0
188
- };
189
- }
190
- return void 0;
191
- }, "parseGecko");
192
- const parseFirefox = /* @__PURE__ */ __name((line, topFrameMeta) => {
193
- const parts = FIREFOX_REGEX.exec(line);
194
- const isEval = parts ? parts[2].includes(" > eval") : false;
195
- if (!isEval && parts) {
196
- debugLog(`parse firefox error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
197
- return {
198
- column: parts[4] ? +parts[4] : topFrameMeta?.column ?? void 0,
199
- file: parts[2],
200
- line: parts[3] ? +parts[3] : topFrameMeta?.line ?? void 0,
201
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
202
- methodName: parts[1] || UNKNOWN_FUNCTION,
203
- raw: line,
204
- type: void 0
205
- };
206
- }
207
- return void 0;
208
- }, "parseFirefox");
209
- const parseReactAndroidNative = /* @__PURE__ */ __name((line) => {
210
- const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);
211
- if (parts) {
212
- debugLog(`parse react android native error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
213
- return {
214
- column: parts[3] ? +parts[3] : void 0,
215
- file: parts[1],
216
- line: parts[2] ? +parts[2] : void 0,
217
- methodName: UNKNOWN_FUNCTION,
218
- raw: line,
219
- type: void 0
220
- };
221
- }
222
- return void 0;
223
- }, "parseReactAndroidNative");
224
- const parse = /* @__PURE__ */ __name((error, { filter, frameLimit = 50 } = {}) => {
225
- let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
226
- const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, "$1") : line;
227
- return cleanedLine.replace(/^\s+|\s+$/g, "");
228
- }).filter((line) => !/\S*(?:Error: |AggregateError:)/.test(line) && line !== "eval code");
229
- if (filter) {
230
- lines = lines.filter((element) => filter(element));
231
- }
232
- lines = lines.slice(0, frameLimit);
233
- return lines.reduce((stack, line, currentIndex) => {
234
- if (!line) {
235
- return stack;
236
- }
237
- if (line.length > 1024) {
238
- return stack;
239
- }
240
- let parseResult;
241
- if (/^\s*in\s.*/.test(line)) {
242
- parseResult = parseNode(line);
243
- } else if (/^.*?\s*at\s.*/.test(line)) {
244
- parseResult = parseChromium(line);
245
- } else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
246
- let topFrameMeta;
247
- if (currentIndex === 0) {
248
- if (error.columnNumber || error.lineNumber) {
249
- topFrameMeta = {
250
- // @ts-expect-error columnNumber and columnNumber property only exists on Firefox
251
- column: error.columnNumber,
252
- // @ts-expect-error columnNumber and lineNumber property only exists on Firefox
253
- line: error.lineNumber,
254
- type: "firefox"
255
- };
256
- } else if (error.line || error.column) {
257
- topFrameMeta = {
258
- // @ts-expect-error column property only exists on safari
259
- column: error.column,
260
- // @ts-expect-error line property only exists on safari
261
- line: error.line,
262
- type: "safari"
263
- };
264
- }
265
- }
266
- parseResult = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
267
- parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
268
- } else {
269
- parseResult = parseReactAndroidNative(line);
270
- }
271
- if (parseResult) {
272
- stack.push(parseResult);
273
- } else {
274
- debugLog(`parse error stack line: "${line}"`, "not parser found");
275
- }
276
- return stack;
277
- }, []);
278
- }, "parse");
279
-
280
- export { parse as default };