@visulima/error 6.0.0-alpha.7 → 6.0.0-alpha.8

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 (24) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/code-frame/index.js +5 -5
  3. package/dist/error/get-error-causes.d.ts +1 -1
  4. package/dist/error/index.js +4 -4
  5. package/dist/error/types.d.ts +1 -1
  6. package/dist/index.js +10 -10
  7. package/dist/packem_shared/{aiFinder-HftEgsry.js → aiFinder-CDaOm_ur.js} +2 -2
  8. package/dist/packem_shared/{aiSolutionResponse-CJBMLS9t.js → aiSolutionResponse-DlSn3Imq.js} +1 -1
  9. package/dist/packem_shared/{deserializeError-BsFrjsrV.js → deserializeError-BEH-kMcX.js} +1 -1
  10. package/dist/packem_shared/{errorHintFinder-DEaeRnRW.js → errorHintFinder-bk-fyNyF.js} +7 -7
  11. package/dist/packem_shared/{formatStackFrameLine-D3_6oSWZ.js → formatStackFrameLine-BaISxse1.js} +4 -4
  12. package/dist/packem_shared/{getErrorCauses-DpUsmuqw.js → getErrorCauses-BLHM3CNA.js} +1 -1
  13. package/dist/packem_shared/{indexToLineColumn-Bg8UW1bU.js → indexToLineColumn-BUb0GPKl.js} +2 -1
  14. package/dist/packem_shared/{parseStacktrace-oQvk7wYp.js → parseStacktrace-B_dIfRHt.js} +44 -32
  15. package/dist/packem_shared/{renderError-C30PRFtU.js → renderError-BVWwJmI2.js} +4 -4
  16. package/dist/packem_shared/{ruleBasedFinder-C2F8rQ30.js → ruleBasedFinder-E1R-t_rj.js} +14 -14
  17. package/dist/packem_shared/{serializeError-e9YW13-X.js → serializeError-CcomaUJN.js} +15 -13
  18. package/dist/solution/ai/ai-prompt.js +3 -3
  19. package/dist/solution/ai/index.js +2 -2
  20. package/dist/solution/index.js +2 -2
  21. package/dist/solution/types.d.ts +1 -1
  22. package/dist/stacktrace/index.js +2 -2
  23. package/dist/stacktrace/types.d.ts +6 -6
  24. package/package.json +2 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## @visulima/error [6.0.0-alpha.8](https://github.com/visulima/visulima/compare/@visulima/error@6.0.0-alpha.7...@visulima/error@6.0.0-alpha.8) (2026-04-08)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **error:** properly fix eslint errors in code ([4f4cf45](https://github.com/visulima/visulima/commit/4f4cf45f223ad0482bb9c0eed14738303662105a))
6
+ * **error:** remove remaining eslint suppressions with proper code fixes ([e92dc33](https://github.com/visulima/visulima/commit/e92dc3372363051cf635a69f918c5f875fd1bd72))
7
+ * **error:** resolve eslint errors ([52639e9](https://github.com/visulima/visulima/commit/52639e902f8bc7b29498ecfb0c546cf9642d7af8))
8
+
9
+ ### Miscellaneous Chores
10
+
11
+ * **error-debugging:** remove empty dependency objects from package.json ([7eb7c8e](https://github.com/visulima/visulima/commit/7eb7c8eba1394e515fa77c0f56baf41c0810de2e))
12
+ * **error:** add tsconfig.eslint.json for type-aware linting ([c5fa576](https://github.com/visulima/visulima/commit/c5fa57628362636cdafc09139d955c60bd1db3d0))
13
+ * **error:** apply prettier formatting ([10704af](https://github.com/visulima/visulima/commit/10704af82a1317a43b5379982617f35953b8d069))
14
+ * **error:** migrate .prettierrc.cjs to prettier.config.js ([15ca04c](https://github.com/visulima/visulima/commit/15ca04cb0de5f026607aef88e98b68a0fffa3366))
15
+
16
+
17
+ ### Dependencies
18
+
19
+ * **@visulima/path:** upgraded to 3.0.0-alpha.8
20
+
1
21
  ## @visulima/error [6.0.0-alpha.7](https://github.com/visulima/visulima/compare/@visulima/error@6.0.0-alpha.6...@visulima/error@6.0.0-alpha.7) (2026-03-26)
2
22
 
3
23
  ### Features
@@ -1,10 +1,10 @@
1
1
  const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
2
2
 
3
- const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
3
+ const rawProcess = globalThis.process ?? /* @__PURE__ */ Object.create(null);
4
4
  const processShims = {
5
5
  versions: {}
6
6
  };
7
- const process = /* @__PURE__ */ new Proxy(_process, {
7
+ const process = /* @__PURE__ */ new Proxy(rawProcess, {
8
8
  get(target, property) {
9
9
  if (property in target) {
10
10
  return target[property];
@@ -81,9 +81,9 @@ const codeFrame = (source, loc, options) => {
81
81
  ...options?.color
82
82
  }
83
83
  };
84
- const hasColumns = loc.start && typeof loc.start.column === "number";
84
+ const hasColumns = typeof loc.start.column === "number";
85
85
  let lines = normalizeLF(source).split("\n");
86
- if (typeof config?.tabWidth === "number") {
86
+ if (typeof config.tabWidth === "number") {
87
87
  lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
88
88
  }
89
89
  const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
@@ -92,7 +92,7 @@ const codeFrame = (source, loc, options) => {
92
92
  let frame = lines.slice(start, end).map((line, index) => {
93
93
  const number = start + 1 + index;
94
94
  const hasMarker = markerLines[number];
95
- const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
95
+ const paddedNumber = ` ${String(number)}`.slice(-numberMaxWidth);
96
96
  const lastMarkerLine = !markerLines[number + 1];
97
97
  const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
98
98
  if (hasMarker) {
@@ -2,5 +2,5 @@ import type { VisulimaError } from "./visulima-error.d.ts";
2
2
  /**
3
3
  * Will return an array of all causes in the error in the order they occurred.
4
4
  */
5
- declare const getErrorCauses: <E = Error | VisulimaError | unknown>(error: E) => E[];
5
+ declare const getErrorCauses: <E = Error | VisulimaError>(error: E) => E[];
6
6
  export default getErrorCauses;
@@ -1,8 +1,8 @@
1
1
  export { default as captureRawStackTrace } from '../packem_shared/captureRawStackTrace-ySw7cU0U.js';
2
- export { default as getErrorCauses } from '../packem_shared/getErrorCauses-DpUsmuqw.js';
3
- export { renderError } from '../packem_shared/renderError-C30PRFtU.js';
4
- export { default as deserializeError } from '../packem_shared/deserializeError-BsFrjsrV.js';
2
+ export { default as getErrorCauses } from '../packem_shared/getErrorCauses-BLHM3CNA.js';
3
+ export { renderError } from '../packem_shared/renderError-BVWwJmI2.js';
4
+ export { default as deserializeError } from '../packem_shared/deserializeError-BEH-kMcX.js';
5
5
  export { addKnownErrorConstructor, isErrorLike } from '../packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
6
6
  export { default as NonError } from '../packem_shared/NonError-D5FGLYKY.js';
7
- export { serialize as serializeError } from '../packem_shared/serializeError-e9YW13-X.js';
7
+ export { serialize as serializeError } from '../packem_shared/serializeError-CcomaUJN.js';
8
8
  export { VisulimaError, isVisulimaError } from '../packem_shared/isVisulimaError-DA7QsCxH.js';
@@ -1,5 +1,5 @@
1
1
  export interface ErrorProperties {
2
- cause?: Error | unknown;
2
+ cause?: unknown;
3
3
  hint?: ErrorHint;
4
4
  location?: ErrorLocation;
5
5
  message?: string;
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.js';
2
- export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-Bg8UW1bU.js';
2
+ export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-BUb0GPKl.js';
3
3
  export { default as aiPrompt } from './solution/ai/ai-prompt.js';
4
- export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-CJBMLS9t.js';
5
- export { default as errorHintFinder } from './packem_shared/errorHintFinder-DEaeRnRW.js';
6
- export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-C2F8rQ30.js';
4
+ export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-DlSn3Imq.js';
5
+ export { default as errorHintFinder } from './packem_shared/errorHintFinder-bk-fyNyF.js';
6
+ export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-E1R-t_rj.js';
7
7
  export { default as NonError } from './packem_shared/NonError-D5FGLYKY.js';
8
8
  export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-ySw7cU0U.js';
9
- export { default as deserializeError } from './packem_shared/deserializeError-BsFrjsrV.js';
10
- export { default as getErrorCauses } from './packem_shared/getErrorCauses-DpUsmuqw.js';
11
- export { default as parseStacktrace } from './packem_shared/parseStacktrace-oQvk7wYp.js';
9
+ export { default as deserializeError } from './packem_shared/deserializeError-BEH-kMcX.js';
10
+ export { default as getErrorCauses } from './packem_shared/getErrorCauses-BLHM3CNA.js';
11
+ export { default as parseStacktrace } from './packem_shared/parseStacktrace-B_dIfRHt.js';
12
12
  export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-DA7QsCxH.js';
13
13
  export { addKnownErrorConstructor, isErrorLike } from './packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
14
- export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-D3_6oSWZ.js';
15
- export { renderError } from './packem_shared/renderError-C30PRFtU.js';
16
- export { serialize as serializeError } from './packem_shared/serializeError-e9YW13-X.js';
14
+ export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-BaISxse1.js';
15
+ export { renderError } from './packem_shared/renderError-BVWwJmI2.js';
16
+ export { serialize as serializeError } from './packem_shared/serializeError-CcomaUJN.js';
@@ -31,7 +31,7 @@ const {
31
31
  } = __cjs_getBuiltinModule("node:os");
32
32
  import { generateText } from 'ai';
33
33
  import aiPrompt from '../solution/ai/ai-prompt.js';
34
- import aiSolutionResponse from './aiSolutionResponse-CJBMLS9t.js';
34
+ import aiSolutionResponse from './aiSolutionResponse-DlSn3Imq.js';
35
35
 
36
36
  const DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
37
37
  const normalizeWindowsPath = (input = "") => {
@@ -140,7 +140,7 @@ const join = (...segments) => {
140
140
  continue;
141
141
  }
142
142
  if (path2.length > 0) {
143
- const pathTrailing = path2[path2.length - 1] === "/";
143
+ const pathTrailing = path2.at(-1) === "/";
144
144
  const segLeading = seg[0] === "/";
145
145
  const both = pathTrailing && segLeading;
146
146
  if (both) {
@@ -21,7 +21,7 @@ const aiSolutionResponse = (rawText) => {
21
21
  ].join("</br></br>");
22
22
  }
23
23
  const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
24
- return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
24
+ return `${description.replaceAll(/"([^"]*)"(?:\s|\.)/g, "<code>$1</code> ")}
25
25
 
26
26
  ## Links
27
27
 
@@ -23,7 +23,7 @@ const reconstructError = (serialized, options, depth) => {
23
23
  return new NonError(JSON.stringify(serialized));
24
24
  }
25
25
  const { cause, errors, message, name, stack, ...properties } = serialized;
26
- const Constructor = getErrorConstructor(name) || Error;
26
+ const Constructor = getErrorConstructor(name) ?? Error;
27
27
  const error = name === "AggregateError" && Array.isArray(errors) ? reconstructAggregateError(Constructor, errors, message, options, depth) : new Constructor(message);
28
28
  if (!error.name && name) {
29
29
  error.name = name;
@@ -1,18 +1,18 @@
1
1
  const errorHintFinder = {
2
- handle: async (error) => {
3
- if (error.hint === void 0 || error.hint === null) {
4
- return void 0;
2
+ handle: (error) => {
3
+ if (error.hint === void 0) {
4
+ return Promise.resolve(void 0);
5
5
  }
6
6
  if (typeof error.hint === "string" && error.hint !== "") {
7
- return { body: error.hint };
7
+ return Promise.resolve({ body: error.hint });
8
8
  }
9
9
  if (typeof error.hint === "object" && typeof error.hint.body === "string") {
10
- return error.hint;
10
+ return Promise.resolve(error.hint);
11
11
  }
12
12
  if (Array.isArray(error.hint)) {
13
- return { body: error.hint.join("\n") };
13
+ return Promise.resolve({ body: error.hint.join("\n") });
14
14
  }
15
- return void 0;
15
+ return Promise.resolve(void 0);
16
16
  },
17
17
  name: "errorHint",
18
18
  priority: 1
@@ -1,8 +1,8 @@
1
1
  const formatStackFrameLine = (frame) => {
2
2
  const method = frame.methodName && frame.methodName !== "<unknown>" ? `${frame.methodName} ` : "";
3
3
  const file = frame.file ?? "<unknown>";
4
- const line = frame.line ?? 0;
5
- const column = frame.column ?? 0;
4
+ const line = String(frame.line ?? 0);
5
+ const column = String(frame.column ?? 0);
6
6
  if (method.trim()) {
7
7
  return ` at ${method}(${file}:${line}:${column})`;
8
8
  }
@@ -11,8 +11,8 @@ const formatStackFrameLine = (frame) => {
11
11
  const formatStacktrace = (frames, options) => {
12
12
  const lines = [];
13
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 || "");
14
+ const headerName = options.header.name ?? "Error";
15
+ const headerMessage = options.header.message ?? "";
16
16
  lines.push(`${headerName}${headerMessage ? ": " : ""}${headerMessage}`);
17
17
  }
18
18
  for (const frame of frames) {
@@ -32,7 +32,7 @@ const getErrorCauses = (error) => {
32
32
  }
33
33
  causes.push(currentError);
34
34
  seen.add(currentError);
35
- if (!currentError.cause) {
35
+ if (typeof currentError !== "object" || !("cause" in currentError)) {
36
36
  break;
37
37
  }
38
38
  currentError = currentError.cause;
@@ -14,9 +14,10 @@ const binarySearch = (element, array) => {
14
14
  }
15
15
  return m;
16
16
  };
17
+ const LINE_BREAK_REGEX = /\n|\r(?!\n)/;
17
18
  const getLineStartIndexes = (string_) => (
18
19
  // eslint-disable-next-line unicorn/no-array-reduce
19
- string_.split(/\n|\r(?!\n)/).reduce(
20
+ string_.split(LINE_BREAK_REGEX).reduce(
20
21
  (accumulator, current) => {
21
22
  accumulator.push(accumulator.at(-1) + current.length + 1);
22
23
  return accumulator;
@@ -1,13 +1,13 @@
1
1
  const debugLog = (message, ...arguments_) => {
2
- if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
2
+ if (process.env.DEBUG && process.env.DEBUG === "true") {
3
3
  console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
4
4
  }
5
5
  };
6
6
  const UNKNOWN_FUNCTION = "<unknown>";
7
7
  const CHROMIUM_REGEX = /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
8
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+)/;
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
11
  const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
12
12
  const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
13
13
  const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
@@ -15,6 +15,14 @@ const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native
15
15
  const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
16
16
  const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
17
17
  const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
18
+ const AT_PREFIX_REGEX = /at\s/;
19
+ const CHROMIUM_EVAL_SPLIT_REGEX = /^(\S+):(\d+):(\d+)$|^(\S+):(\d+)$/;
20
+ const TRIM_REGEX = /^\s+|\s+$/g;
21
+ const ERROR_LINE_REGEX = /\S*(?:Error: |AggregateError:)/;
22
+ const ANONYMOUS_FUNCTION_REGEX = /^Anonymous function$/;
23
+ const NODE_LINE_REGEX = /^\s*in\s.*/;
24
+ const CHROMIUM_LINE_REGEX = /^.*?\s*at\s.*/;
25
+ const GECKO_LINE_REGEX = /^.*?\s*@.*|\[native code\]/;
18
26
  const extractSafariExtensionDetails = (methodName, url) => {
19
27
  const isSafariExtension = methodName.includes("safari-extension");
20
28
  const isSafariWebExtension = methodName.includes("safari-web-extension");
@@ -40,7 +48,7 @@ const parseNode = (line) => {
40
48
  column: split[2] ? +split[2] : void 0,
41
49
  file: split[0],
42
50
  line: split[1] ? +split[1] : void 0,
43
- methodName: nestedNode[1] || UNKNOWN_FUNCTION,
51
+ methodName: nestedNode[1] ?? UNKNOWN_FUNCTION,
44
52
  raw: line,
45
53
  type: void 0
46
54
  };
@@ -50,9 +58,9 @@ const parseNode = (line) => {
50
58
  debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
51
59
  const trace = {
52
60
  column: node[4] ? +node[4] : void 0,
53
- file: node[2] ? node[2].replace(/at\s/, "") : void 0,
61
+ file: node[2] ? node[2].replace(AT_PREFIX_REGEX, "") : void 0,
54
62
  line: node[3] ? +node[3] : void 0,
55
- methodName: node[1] || UNKNOWN_FUNCTION,
63
+ methodName: node[1] ?? UNKNOWN_FUNCTION,
56
64
  raw: line,
57
65
  type: line.startsWith("internal") ? "internal" : void 0
58
66
  };
@@ -72,7 +80,7 @@ const parseChromium = (line) => {
72
80
  if (isEval) {
73
81
  const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
74
82
  if (subMatch) {
75
- const split = /^(\S+):(\d+):(\d+)$|^(\S+):(\d+)$/.exec(subMatch[1]);
83
+ const split = CHROMIUM_EVAL_SPLIT_REGEX.exec(subMatch[1]);
76
84
  if (split) {
77
85
  parts[2] = split[4] ?? split[1];
78
86
  parts[3] = split[5] ?? split[2];
@@ -94,14 +102,14 @@ const parseChromium = (line) => {
94
102
  const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
95
103
  if (windowsSubMatch) {
96
104
  windowsParts = {
97
- column: windowsSubMatch[5] ? +windowsSubMatch[5] : void 0,
98
- file: windowsSubMatch[3],
99
- line: windowsSubMatch[4] ? +windowsSubMatch[4] : void 0
105
+ column: windowsSubMatch[4] ? +windowsSubMatch[4] : void 0,
106
+ file: windowsSubMatch[2],
107
+ line: windowsSubMatch[3] ? +windowsSubMatch[3] : void 0
100
108
  };
101
109
  evalOrigin = {
102
- column: windowsSubMatch[8] ? +windowsSubMatch[8] : void 0,
103
- file: windowsSubMatch[2],
104
- line: windowsSubMatch[7] ? +windowsSubMatch[7] : void 0,
110
+ column: windowsSubMatch[6] ? +windowsSubMatch[6] : void 0,
111
+ file: windowsSubMatch[1],
112
+ line: windowsSubMatch[5] ? +windowsSubMatch[5] : void 0,
105
113
  methodName: "eval",
106
114
  raw: windowsSubMatch[0],
107
115
  type: "eval"
@@ -111,7 +119,7 @@ const parseChromium = (line) => {
111
119
  }
112
120
  const [methodName, file] = extractSafariExtensionDetails(
113
121
  // Normalize IE's 'Anonymous function'
114
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
122
+ parts[1] ? parts[1].replace(ANONYMOUS_FUNCTION_REGEX, "<anonymous>") : UNKNOWN_FUNCTION,
115
123
  parts[2]
116
124
  );
117
125
  const trace = {
@@ -156,7 +164,7 @@ const parseGecko = (line, topFrameMeta) => {
156
164
  }
157
165
  const [methodName, file] = extractSafariExtensionDetails(
158
166
  // Normalize IE's 'Anonymous function'
159
- parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
167
+ parts[1] ? parts[1].replace(ANONYMOUS_FUNCTION_REGEX, "<anonymous>") : UNKNOWN_FUNCTION,
160
168
  parts[3]
161
169
  );
162
170
  let column;
@@ -193,6 +201,7 @@ const parseFirefox = (line, topFrameMeta) => {
193
201
  column: parts[4] ? +parts[4] : topFrameMeta?.column ?? void 0,
194
202
  file: parts[2],
195
203
  line: parts[3] ? +parts[3] : topFrameMeta?.line ?? void 0,
204
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- intentionally using || to treat empty string as unknown
196
205
  methodName: parts[1] || UNKNOWN_FUNCTION,
197
206
  raw: line,
198
207
  type: void 0
@@ -216,10 +225,12 @@ const parseReactAndroidNative = (line) => {
216
225
  return void 0;
217
226
  };
218
227
  const parseStacktrace = (error, { filter, frameLimit = 50 } = {}) => {
219
- let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
228
+ const errorRecord = error;
229
+ const rawStack = typeof errorRecord.stacktrace === "string" ? errorRecord.stacktrace : error.stack ?? "";
230
+ let lines = rawStack.split("\n").map((line) => {
220
231
  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");
232
+ return cleanedLine.replaceAll(TRIM_REGEX, "");
233
+ }).filter((line) => !ERROR_LINE_REGEX.test(line) && line !== "eval code");
223
234
  if (filter) {
224
235
  lines = lines.filter((element) => filter(element));
225
236
  }
@@ -232,32 +243,33 @@ const parseStacktrace = (error, { filter, frameLimit = 50 } = {}) => {
232
243
  return stack;
233
244
  }
234
245
  let parseResult;
235
- if (/^\s*in\s.*/.test(line)) {
246
+ if (NODE_LINE_REGEX.test(line)) {
236
247
  parseResult = parseNode(line);
237
- } else if (/^.*?\s*at\s.*/.test(line)) {
248
+ } else if (CHROMIUM_LINE_REGEX.test(line)) {
238
249
  parseResult = parseChromium(line);
239
- } else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
250
+ } else if (GECKO_LINE_REGEX.test(line)) {
240
251
  let topFrameMeta;
241
252
  if (currentIndex === 0) {
242
- if (error.columnNumber || error.lineNumber) {
253
+ const browserError = error;
254
+ const columnNumber = browserError.columnNumber;
255
+ const lineNumber = browserError.lineNumber;
256
+ const safariLine = browserError.line;
257
+ const safariColumn = browserError.column;
258
+ if (columnNumber || lineNumber) {
243
259
  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,
260
+ column: columnNumber,
261
+ line: lineNumber,
248
262
  type: "firefox"
249
263
  };
250
- } else if (error.line || error.column) {
264
+ } else if (safariLine || safariColumn) {
251
265
  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,
266
+ column: safariColumn,
267
+ line: safariLine,
256
268
  type: "safari"
257
269
  };
258
270
  }
259
271
  }
260
- parseResult = parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
272
+ parseResult = parseFirefox(line, topFrameMeta) ?? parseGecko(line, topFrameMeta);
261
273
  } else {
262
274
  parseResult = parseReactAndroidNative(line);
263
275
  }
@@ -31,11 +31,11 @@ const {
31
31
  fileURLToPath
32
32
  } = __cjs_getBuiltinModule("node:url");
33
33
  import { codeFrame } from '../code-frame/index.js';
34
- import parseStacktrace from './parseStacktrace-oQvk7wYp.js';
34
+ import parseStacktrace from './parseStacktrace-B_dIfRHt.js';
35
35
 
36
36
  const getPrefix = (prefix, indentation, deep) => {
37
37
  if (deep === 0) {
38
- return prefix.toString();
38
+ return prefix;
39
39
  }
40
40
  if (indentation === " ") {
41
41
  return prefix + " ".repeat(deep);
@@ -63,7 +63,7 @@ const getHint = (error, { color, indentation, prefix }, deep) => {
63
63
  let message = "";
64
64
  if (Array.isArray(error.hint)) {
65
65
  for (const line of error.hint) {
66
- message += `${(spaces + line).toString()}
66
+ message += `${spaces + line}
67
67
  `;
68
68
  }
69
69
  } else {
@@ -76,7 +76,7 @@ const getMainFrame = (trace, { color, cwd: cwdPath, displayShortPath, indentatio
76
76
  const { fileLine, method } = color;
77
77
  return `${getPrefix(prefix, indentation, deep)}at ${trace.methodName ? `${method(trace.methodName)} ` : ""}${fileLine(filePath)}:${fileLine(
78
78
  trace.line?.toString() ?? ""
79
- )}`.toString();
79
+ )}`;
80
80
  };
81
81
  const getCode = (trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
82
82
  if (trace.file === void 0) {
@@ -18,7 +18,7 @@ const rules = [
18
18
  {
19
19
  name: "esm-cjs-interop",
20
20
  test: (error) => {
21
- const message = (error?.message || String(error || "")).toString();
21
+ const { message } = error;
22
22
  if (has(
23
23
  message,
24
24
  "err_require_esm",
@@ -52,7 +52,7 @@ const rules = [
52
52
  {
53
53
  name: "missing-default-export",
54
54
  test: (error) => {
55
- const message = (error?.message || String(error || "")).toString();
55
+ const { message } = error;
56
56
  if (has(message, "default export not found", "has no default export", "does not provide an export named 'default'", "is not exported from")) {
57
57
  return {
58
58
  md: [
@@ -73,7 +73,7 @@ const rules = [
73
73
  {
74
74
  name: "port-in-use",
75
75
  test: (error) => {
76
- const message = (error?.message || String(error || "")).toString();
76
+ const { message } = error;
77
77
  if (has(message, "eaddrinuse", "address already in use", "listen eaddrinuse")) {
78
78
  return {
79
79
  md: [
@@ -96,7 +96,7 @@ const rules = [
96
96
  {
97
97
  name: "file-not-found-or-case",
98
98
  test: (error, file) => {
99
- const message = (error?.message || String(error || "")).toString();
99
+ const { message } = error;
100
100
  if (has(message, "enoent", "module not found", "cannot find module")) {
101
101
  return {
102
102
  md: [
@@ -104,7 +104,7 @@ const rules = [
104
104
  "If using TS path aliases, verify `tsconfig.paths` and bundler aliases.",
105
105
  "",
106
106
  "Current file:",
107
- code(`${file.file}:${file.line}`)
107
+ code(`${file.file}:${String(file.line)}`)
108
108
  ].join("\n"),
109
109
  title: "Missing file or path case mismatch"
110
110
  };
@@ -115,7 +115,7 @@ const rules = [
115
115
  {
116
116
  name: "ts-path-mapping",
117
117
  test: (error) => {
118
- const message = (error?.message || String(error || "")).toString();
118
+ const { message } = error;
119
119
  if (has(message, "ts2307", "cannot find module") || message.includes("TS2307")) {
120
120
  return {
121
121
  md: [
@@ -139,7 +139,7 @@ const rules = [
139
139
  {
140
140
  name: "network-dns-enotfound",
141
141
  test: (error) => {
142
- const message = (error?.message || String(error || "")).toString();
142
+ const { message } = error;
143
143
  if (has(message, "enotfound", "getaddrinfo enotfound", "dns", "fetch failed", "ecconnrefused", "econnrefused")) {
144
144
  return {
145
145
  md: [
@@ -161,7 +161,7 @@ const rules = [
161
161
  {
162
162
  name: "undefined-property",
163
163
  test: (error) => {
164
- const message = (error?.message || String(error || "")).toString();
164
+ const { message } = error;
165
165
  if (has(message, "cannot read properties of undefined", "reading '")) {
166
166
  return {
167
167
  md: [
@@ -181,23 +181,23 @@ const rules = [
181
181
  }
182
182
  ];
183
183
  const ruleBasedFinder = {
184
- handle: async (error, file) => {
184
+ handle: (error, file) => {
185
185
  try {
186
186
  const matches = rules.map((r) => {
187
187
  return { match: r.test(error, file), rule: r };
188
188
  }).filter((x) => Boolean(x.match));
189
189
  if (matches.length === 0) {
190
- return void 0;
190
+ return Promise.resolve(void 0);
191
191
  }
192
- const sections = matches.toSorted((a, b) => (a.match.priority || 0) - (b.match.priority || 0)).map((m) => `#### ${m.match.title}
192
+ const sections = matches.toSorted((a, b) => (a.match.priority ?? 0) - (b.match.priority ?? 0)).map((m) => `#### ${m.match.title}
193
193
 
194
194
  ${m.match.md}`).join("\n\n---\n\n");
195
195
  if (sections === "") {
196
- return void 0;
196
+ return Promise.resolve(void 0);
197
197
  }
198
- return { body: sections, header: "### Potential fixes detected" };
198
+ return Promise.resolve({ body: sections, header: "### Potential fixes detected" });
199
199
  } catch {
200
- return void 0;
200
+ return Promise.resolve(void 0);
201
201
  }
202
202
  },
203
203
  name: "ruleBasedHints",
@@ -38,9 +38,6 @@ const ErrorProto = Object.create(
38
38
 
39
39
  const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
40
40
  const makePropertiesEnumerable = (object) => {
41
- if (!object || typeof object !== "object") {
42
- return;
43
- }
44
41
  const props = Object.getOwnPropertyNames(object);
45
42
  for (const prop of props) {
46
43
  const descriptor = Object.getOwnPropertyDescriptor(object, prop);
@@ -61,7 +58,11 @@ const toJSON = (from) => {
61
58
  toJsonWasCalled.add(from);
62
59
  const json = from.toJSON();
63
60
  toJsonWasCalled.delete(from);
64
- if (json && typeof json === "object" && Object.isExtensible(json)) {
61
+ if (
62
+ // Only make properties enumerable if the object is extensible
63
+ // Non-extensible objects (like when toJSON returns 'this') should preserve original enumerability
64
+ Object.isExtensible(json)
65
+ ) {
65
66
  makePropertiesEnumerable(json);
66
67
  }
67
68
  return json;
@@ -70,7 +71,7 @@ const serializeValue = (value, seen, depth, options) => {
70
71
  if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
71
72
  return "[object Buffer]";
72
73
  }
73
- if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
74
+ if (value !== null && typeof value === "object" && "pipe" in value && typeof value.pipe === "function") {
74
75
  return "[object Stream]";
75
76
  }
76
77
  if (value instanceof Error) {
@@ -80,17 +81,17 @@ const serializeValue = (value, seen, depth, options) => {
80
81
  depth += 1;
81
82
  return _serialize(value, options, seen, depth);
82
83
  }
83
- if (options.useToJSON && typeof value.toJSON === "function") {
84
+ if (options.useToJSON && value !== null && typeof value === "object" && "toJSON" in value && typeof value.toJSON === "function") {
84
85
  return value.toJSON();
85
86
  }
86
- if (typeof value === "object" && value instanceof Date) {
87
+ if (value instanceof Date) {
87
88
  return value.toISOString();
88
89
  }
89
90
  if (typeof value === "function") {
90
91
  return `[Function: ${value.name || "anonymous"}]`;
91
92
  }
92
93
  if (typeof value === "bigint") {
93
- return `${value}n`;
94
+ return `${String(value)}n`;
94
95
  }
95
96
  if (isPlainObject(value)) {
96
97
  if (options.maxDepth !== void 0 && options.maxDepth !== Number.POSITIVE_INFINITY && depth + 1 >= options.maxDepth) {
@@ -160,9 +161,10 @@ const _serialize = (error, options, seen, depth) => {
160
161
  writable: true
161
162
  });
162
163
  }
163
- if (error.cause !== void 0 && error.cause !== null) {
164
- if (error.cause instanceof Error) {
165
- if (seen.has(error.cause)) {
164
+ const causeValue = error.cause;
165
+ if (causeValue !== void 0 && causeValue !== null) {
166
+ if (causeValue instanceof Error) {
167
+ if (seen.has(causeValue)) {
166
168
  Object.defineProperty(protoError, "cause", {
167
169
  configurable: true,
168
170
  enumerable: true,
@@ -173,12 +175,12 @@ const _serialize = (error, options, seen, depth) => {
173
175
  Object.defineProperty(protoError, "cause", {
174
176
  configurable: true,
175
177
  enumerable: true,
176
- value: _serialize(error.cause, options, seen, depth),
178
+ value: _serialize(causeValue, options, seen, depth),
177
179
  writable: true
178
180
  });
179
181
  }
180
182
  } else {
181
- const serializedCause = serializeValue(error.cause, seen, depth, options);
183
+ const serializedCause = serializeValue(causeValue, seen, depth, options);
182
184
  Object.defineProperty(protoError, "cause", {
183
185
  configurable: true,
184
186
  enumerable: true,
@@ -2,7 +2,7 @@ const aiPrompt = ({
2
2
  applicationType,
3
3
  error,
4
4
  file
5
- }) => `You are a very skilled ${file.language} programmer.
5
+ }) => `You are a very skilled ${file.language ?? "unknown"} programmer.
6
6
 
7
7
  ${applicationType ? `You are working on a ${applicationType} application.` : ""}
8
8
 
@@ -21,13 +21,13 @@ ENDLINKS
21
21
 
22
22
  Here comes the context and the exception message:
23
23
 
24
- Line: ${file.line}
24
+ Line: ${String(file.line)}
25
25
 
26
26
  File:
27
27
  ${file.file}
28
28
 
29
29
  Snippet including line numbers:
30
- ${file.snippet}
30
+ ${file.snippet ?? ""}
31
31
 
32
32
  Exception class:
33
33
  ${error.name}
@@ -1,3 +1,3 @@
1
- export { default as aiFinder } from '../../packem_shared/aiFinder-HftEgsry.js';
1
+ export { default as aiFinder } from '../../packem_shared/aiFinder-CDaOm_ur.js';
2
2
  export { default as aiPrompt } from './ai-prompt.js';
3
- export { default as aiSolutionResponse } from '../../packem_shared/aiSolutionResponse-CJBMLS9t.js';
3
+ export { default as aiSolutionResponse } from '../../packem_shared/aiSolutionResponse-DlSn3Imq.js';
@@ -1,2 +1,2 @@
1
- export { default as errorHintFinder } from '../packem_shared/errorHintFinder-DEaeRnRW.js';
2
- export { default as ruleBasedFinder } from '../packem_shared/ruleBasedFinder-C2F8rQ30.js';
1
+ export { default as errorHintFinder } from '../packem_shared/errorHintFinder-bk-fyNyF.js';
2
+ export { default as ruleBasedFinder } from '../packem_shared/ruleBasedFinder-E1R-t_rj.js';
@@ -6,7 +6,7 @@ export type SolutionFinderFile = {
6
6
  file: string;
7
7
  language?: string;
8
8
  line: number;
9
- snippet?: string | undefined;
9
+ snippet?: string;
10
10
  };
11
11
  export type SolutionFinder = {
12
12
  handle: (error: any, file: SolutionFinderFile) => Promise<Solution | undefined>;
@@ -1,2 +1,2 @@
1
- export { default as parseStacktrace } from '../packem_shared/parseStacktrace-oQvk7wYp.js';
2
- export { formatStackFrameLine, formatStacktrace } from '../packem_shared/formatStackFrameLine-D3_6oSWZ.js';
1
+ export { default as parseStacktrace } from '../packem_shared/parseStacktrace-B_dIfRHt.js';
2
+ export { formatStackFrameLine, formatStacktrace } from '../packem_shared/formatStackFrameLine-BaISxse1.js';
@@ -1,10 +1,10 @@
1
1
  export type TraceType = "eval" | "internal" | "native" | undefined;
2
2
  export interface Trace {
3
- column: number | undefined;
4
- evalOrigin?: Trace | undefined;
5
- file: string | undefined;
6
- line: number | undefined;
7
- methodName: string | undefined;
3
+ column?: number;
4
+ evalOrigin?: Trace;
5
+ file?: string;
6
+ line?: number;
7
+ methodName?: string;
8
8
  raw: string;
9
- type?: TraceType | undefined;
9
+ type?: TraceType;
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/error",
3
- "version": "6.0.0-alpha.7",
3
+ "version": "6.0.0-alpha.8",
4
4
  "description": "Error with more than just a message, stacktrace parsing.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -99,16 +99,14 @@
99
99
  "CHANGELOG.md",
100
100
  "LICENSE.md"
101
101
  ],
102
- "dependencies": {},
103
102
  "peerDependencies": {
104
- "ai": "6.0.134"
103
+ "ai": "6.0.154"
105
104
  },
106
105
  "peerDependenciesMeta": {
107
106
  "ai": {
108
107
  "optional": true
109
108
  }
110
109
  },
111
- "optionalDependencies": {},
112
110
  "engines": {
113
111
  "node": ">=22.13 <=25.x"
114
112
  },