@visulima/error 4.6.0 → 4.6.2
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 +20 -0
- package/dist/code-frame/index.cjs +6 -136
- package/dist/code-frame/index.mjs +6 -131
- package/dist/error/index.cjs +1 -25
- package/dist/error/index.mjs +1 -8
- package/dist/index.cjs +1 -43
- package/dist/index.mjs +1 -16
- package/dist/packem_shared/NonError-CQn4sdxd.cjs +1 -0
- package/dist/packem_shared/NonError-CS10kwil.mjs +1 -0
- package/dist/packem_shared/addKnownErrorConstructor-B5dNFGsR.cjs +1 -0
- package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.mjs +1 -0
- package/dist/packem_shared/aiFinder-Be-xHFVO.mjs +1 -0
- package/dist/packem_shared/aiFinder-CN0pneE2.cjs +1 -0
- package/dist/packem_shared/aiSolutionResponse-C5apAmTu.cjs +10 -0
- package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.mjs +10 -0
- package/dist/packem_shared/captureRawStackTrace-B9d1821F.cjs +1 -0
- package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.mjs +1 -0
- package/dist/packem_shared/deserializeError-2C6o7QF7.cjs +1 -0
- package/dist/packem_shared/deserializeError-tzZhIV70.mjs +1 -0
- package/dist/packem_shared/errorHintFinder-C_g0nvml.mjs +2 -0
- package/dist/packem_shared/errorHintFinder-DRCn1Ysx.cjs +2 -0
- package/dist/packem_shared/formatStackFrameLine-DD2DUdW0.cjs +2 -0
- package/dist/packem_shared/formatStackFrameLine-iU54KA81.mjs +2 -0
- package/dist/packem_shared/getErrorCauses-B7_Z_gEF.cjs +1 -0
- package/dist/packem_shared/getErrorCauses-D025FGyO.mjs +1 -0
- package/dist/packem_shared/index-CLFYRLyq.mjs +1 -0
- package/dist/packem_shared/index-CqSGigts.cjs +1 -0
- package/dist/packem_shared/indexToLineColumn-B1F7aNZh.mjs +1 -0
- package/dist/packem_shared/indexToLineColumn-C_v57REF.cjs +1 -0
- package/dist/packem_shared/isVisulimaError-CrvBm0kw.cjs +1 -0
- package/dist/packem_shared/isVisulimaError-jVZgumOU.mjs +1 -0
- package/dist/packem_shared/parseStacktrace-Dnxnc4PL.mjs +2 -0
- package/dist/packem_shared/parseStacktrace-MW4-SLXl.cjs +2 -0
- package/dist/packem_shared/renderError-D7R71d_7.mjs +18 -0
- package/dist/packem_shared/renderError-D8XJnkIF.cjs +18 -0
- package/dist/packem_shared/ruleBasedFinder-B1jRHBM_.cjs +34 -0
- package/dist/packem_shared/ruleBasedFinder-P88d0gpK.mjs +34 -0
- package/dist/packem_shared/serializeError-7S1IG6zs.cjs +1 -0
- package/dist/packem_shared/serializeError-Bc-QciX0.mjs +1 -0
- package/dist/solution/ai/ai-prompt.cjs +7 -17
- package/dist/solution/ai/ai-prompt.mjs +7 -15
- package/dist/solution/ai/index.cjs +1 -13
- package/dist/solution/ai/index.mjs +1 -3
- package/dist/solution/index.cjs +1 -11
- package/dist/solution/index.mjs +1 -2
- package/dist/stacktrace/index.cjs +1 -12
- package/dist/stacktrace/index.mjs +1 -2
- package/package.json +1 -1
- package/dist/packem_shared/NonError-BrwMc2LE.mjs +0 -13
- package/dist/packem_shared/NonError-DqwGL5Cy.cjs +0 -15
- package/dist/packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs +0 -32
- package/dist/packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs +0 -39
- package/dist/packem_shared/aiFinder-BR9Pq804.cjs +0 -259
- package/dist/packem_shared/aiFinder-CFHvOjD8.mjs +0 -257
- package/dist/packem_shared/aiSolutionResponse-BaN1M990.mjs +0 -36
- package/dist/packem_shared/aiSolutionResponse-Cqi0mFxy.cjs +0 -38
- package/dist/packem_shared/captureRawStackTrace-ClSI1tHb.cjs +0 -14
- package/dist/packem_shared/captureRawStackTrace-Tl3Rqkat.mjs +0 -12
- package/dist/packem_shared/deserializeError-Be3qOGBQ.cjs +0 -120
- package/dist/packem_shared/deserializeError-DuzHucBb.mjs +0 -118
- package/dist/packem_shared/errorHintFinder-CQy_qIK3.mjs +0 -23
- package/dist/packem_shared/errorHintFinder-DZugFHq0.cjs +0 -25
- package/dist/packem_shared/formatStackFrameLine-DcXSX--m.cjs +0 -31
- package/dist/packem_shared/formatStackFrameLine-DqkmKWH3.mjs +0 -26
- package/dist/packem_shared/getErrorCauses-CG_JRE6j.mjs +0 -24
- package/dist/packem_shared/getErrorCauses-miTeYJEG.cjs +0 -26
- package/dist/packem_shared/index-BmoOJLvu.mjs +0 -12
- package/dist/packem_shared/index-C53Tqb7g.cjs +0 -14
- package/dist/packem_shared/indexToLineColumn-CKQKtKEK.mjs +0 -52
- package/dist/packem_shared/indexToLineColumn-Cro5eT8v.cjs +0 -54
- package/dist/packem_shared/isVisulimaError-Bb1_TB6w.cjs +0 -44
- package/dist/packem_shared/isVisulimaError-zyd80Gui.mjs +0 -39
- package/dist/packem_shared/parseStacktrace-BlguTUcF.mjs +0 -275
- package/dist/packem_shared/parseStacktrace-woJgU2XY.cjs +0 -277
- package/dist/packem_shared/renderError-Cn8M0fQ3.mjs +0 -180
- package/dist/packem_shared/renderError-n3kXGdYj.cjs +0 -184
- package/dist/packem_shared/ruleBasedFinder-Cbmc6N7f.mjs +0 -227
- package/dist/packem_shared/ruleBasedFinder-CkybTSHw.cjs +0 -229
- package/dist/packem_shared/serializeError-DHIelq5o.mjs +0 -144
- package/dist/packem_shared/serializeError-Dt7oFM2R.cjs +0 -148
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { relative } from 'node:path';
|
|
3
|
-
import { cwd } from 'node:process';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { codeFrame } from '../code-frame/index.mjs';
|
|
6
|
-
import parseStacktrace from './parseStacktrace-BlguTUcF.mjs';
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
const getPrefix = /* @__PURE__ */ __name((prefix, indentation, deep) => {
|
|
11
|
-
if (deep === 0) {
|
|
12
|
-
return prefix.toString();
|
|
13
|
-
}
|
|
14
|
-
if (indentation === " ") {
|
|
15
|
-
return prefix + " ".repeat(deep);
|
|
16
|
-
}
|
|
17
|
-
return prefix + " ".repeat(indentation * deep);
|
|
18
|
-
}, "getPrefix");
|
|
19
|
-
const getRelativePath = /* @__PURE__ */ __name((filePath, cwdPath) => {
|
|
20
|
-
const path = filePath.replace("async file:", "file:");
|
|
21
|
-
return relative(cwdPath, path.startsWith("file:") ? fileURLToPath(path) : path);
|
|
22
|
-
}, "getRelativePath");
|
|
23
|
-
const getTitleText = /* @__PURE__ */ __name((error, hideErrorTitle, color) => {
|
|
24
|
-
if (hideErrorTitle) {
|
|
25
|
-
return color.title(error.message);
|
|
26
|
-
}
|
|
27
|
-
const messagePart = error.message ? `: ${error.message}` : "";
|
|
28
|
-
return color.title(error.name + messagePart);
|
|
29
|
-
}, "getTitleText");
|
|
30
|
-
const getMessage = /* @__PURE__ */ __name((error, { color, hideErrorTitle, indentation, prefix }, deep) => `${getPrefix(prefix, indentation, deep)}${getTitleText(error, hideErrorTitle, color)}
|
|
31
|
-
`, "getMessage");
|
|
32
|
-
const getHint = /* @__PURE__ */ __name((error, { color, indentation, prefix }, deep) => {
|
|
33
|
-
if (error.hint === void 0) {
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
const spaces = getPrefix(prefix, indentation, deep);
|
|
37
|
-
let message = "";
|
|
38
|
-
if (Array.isArray(error.hint)) {
|
|
39
|
-
for (const line of error.hint) {
|
|
40
|
-
message += `${(spaces + line).toString()}
|
|
41
|
-
`;
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
message += spaces + error.hint;
|
|
45
|
-
}
|
|
46
|
-
return color.hint(message);
|
|
47
|
-
}, "getHint");
|
|
48
|
-
const getMainFrame = /* @__PURE__ */ __name((trace, { color, cwd: cwdPath, displayShortPath, indentation, prefix }, deep = 0) => {
|
|
49
|
-
const filePath = displayShortPath ? getRelativePath(trace.file, cwdPath) : trace.file;
|
|
50
|
-
const { fileLine, method } = color;
|
|
51
|
-
return `${getPrefix(prefix, indentation, deep)}at ${trace.methodName ? `${method(trace.methodName)} ` : ""}${fileLine(filePath)}:${fileLine(
|
|
52
|
-
trace.line?.toString() ?? ""
|
|
53
|
-
)}`.toString();
|
|
54
|
-
}, "getMainFrame");
|
|
55
|
-
const getCode = /* @__PURE__ */ __name((trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
|
|
56
|
-
if (trace.file === void 0) {
|
|
57
|
-
return void 0;
|
|
58
|
-
}
|
|
59
|
-
const filePath = trace.file.replace("file://", "");
|
|
60
|
-
if (!existsSync(filePath)) {
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
63
|
-
const fileContent = readFileSync(filePath, "utf8");
|
|
64
|
-
return codeFrame(
|
|
65
|
-
fileContent,
|
|
66
|
-
{
|
|
67
|
-
start: { column: trace.column, line: trace.line }
|
|
68
|
-
},
|
|
69
|
-
{ color, linesAbove, linesBelow, prefix: getPrefix(prefix, indentation, deep), showGutter, showLineNumbers, tabWidth }
|
|
70
|
-
);
|
|
71
|
-
}, "getCode");
|
|
72
|
-
const getErrors = /* @__PURE__ */ __name((error, options, deep) => {
|
|
73
|
-
if (error.errors.length === 0) {
|
|
74
|
-
return void 0;
|
|
75
|
-
}
|
|
76
|
-
let message = `${getPrefix(options.prefix, options.indentation, deep)}Errors:
|
|
77
|
-
|
|
78
|
-
`;
|
|
79
|
-
let first = true;
|
|
80
|
-
for (const error_ of error.errors) {
|
|
81
|
-
if (first) {
|
|
82
|
-
first = false;
|
|
83
|
-
} else {
|
|
84
|
-
message += "\n\n";
|
|
85
|
-
}
|
|
86
|
-
message += internalRenderError(error_, { ...options, framesMaxLimit: 1, hideErrorCodeView: options.hideErrorErrorsCodeView }, deep + 1);
|
|
87
|
-
}
|
|
88
|
-
return `
|
|
89
|
-
${message}`;
|
|
90
|
-
}, "getErrors");
|
|
91
|
-
const getCause = /* @__PURE__ */ __name((error, options, deep) => {
|
|
92
|
-
let message = `${getPrefix(options.prefix, options.indentation, deep)}Caused by:
|
|
93
|
-
|
|
94
|
-
`;
|
|
95
|
-
const cause = error.cause;
|
|
96
|
-
message += getMessage(cause, options, deep);
|
|
97
|
-
const stacktrace = parseStacktrace(cause);
|
|
98
|
-
const mainFrame = stacktrace.shift();
|
|
99
|
-
const hint = getHint(cause, options, deep);
|
|
100
|
-
if (hint) {
|
|
101
|
-
message += `${hint}
|
|
102
|
-
`;
|
|
103
|
-
}
|
|
104
|
-
if (mainFrame) {
|
|
105
|
-
message += getMainFrame(mainFrame, options, deep);
|
|
106
|
-
if (!options.hideErrorCauseCodeView) {
|
|
107
|
-
const code = getCode(mainFrame, options, deep);
|
|
108
|
-
if (code !== void 0) {
|
|
109
|
-
message += `
|
|
110
|
-
${code}`;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (cause.cause) {
|
|
115
|
-
message += `
|
|
116
|
-
${getCause(cause, options, deep + 1)}`;
|
|
117
|
-
} else if (cause instanceof AggregateError) {
|
|
118
|
-
const errors = getErrors(cause, options, deep);
|
|
119
|
-
if (errors !== void 0) {
|
|
120
|
-
message += `
|
|
121
|
-
${errors}`;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return `
|
|
125
|
-
${message}`;
|
|
126
|
-
}, "getCause");
|
|
127
|
-
const getStacktrace = /* @__PURE__ */ __name((stack, options) => (stack.length > 0 ? "\n" : "") + stack.map((frame) => getMainFrame(frame, options)).join("\n"), "getStacktrace");
|
|
128
|
-
const internalRenderError = /* @__PURE__ */ __name((error, options, deep) => {
|
|
129
|
-
const config = {
|
|
130
|
-
cwd: cwd(),
|
|
131
|
-
displayShortPath: false,
|
|
132
|
-
filterStacktrace: void 0,
|
|
133
|
-
framesMaxLimit: Number.POSITIVE_INFINITY,
|
|
134
|
-
hideErrorCauseCodeView: false,
|
|
135
|
-
hideErrorCodeView: false,
|
|
136
|
-
hideErrorErrorsCodeView: false,
|
|
137
|
-
hideErrorTitle: false,
|
|
138
|
-
hideMessage: false,
|
|
139
|
-
indentation: 4,
|
|
140
|
-
linesAbove: 2,
|
|
141
|
-
linesBelow: 3,
|
|
142
|
-
prefix: "",
|
|
143
|
-
showGutter: true,
|
|
144
|
-
showLineNumbers: true,
|
|
145
|
-
tabWidth: 4,
|
|
146
|
-
...options,
|
|
147
|
-
color: {
|
|
148
|
-
fileLine: /* @__PURE__ */ __name((value) => value, "fileLine"),
|
|
149
|
-
gutter: /* @__PURE__ */ __name((value) => value, "gutter"),
|
|
150
|
-
hint: /* @__PURE__ */ __name((value) => value, "hint"),
|
|
151
|
-
marker: /* @__PURE__ */ __name((value) => value, "marker"),
|
|
152
|
-
message: /* @__PURE__ */ __name((value) => value, "message"),
|
|
153
|
-
method: /* @__PURE__ */ __name((value) => value, "method"),
|
|
154
|
-
title: /* @__PURE__ */ __name((value) => value, "title"),
|
|
155
|
-
...options.color
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
const stack = parseStacktrace(error, {
|
|
159
|
-
filter: options.filterStacktrace,
|
|
160
|
-
frameLimit: config.framesMaxLimit
|
|
161
|
-
});
|
|
162
|
-
const mainFrame = stack.shift();
|
|
163
|
-
return [
|
|
164
|
-
options.hideMessage ? void 0 : getMessage(error, config, deep),
|
|
165
|
-
getHint(error, config, deep),
|
|
166
|
-
mainFrame ? getMainFrame(mainFrame, config, deep) : void 0,
|
|
167
|
-
mainFrame && !config.hideErrorCodeView ? getCode(mainFrame, config, deep) : void 0,
|
|
168
|
-
error instanceof AggregateError ? getErrors(error, config, deep) : void 0,
|
|
169
|
-
error.cause === void 0 ? void 0 : getCause(error, config, deep),
|
|
170
|
-
stack.length > 0 ? getStacktrace(stack, config) : void 0
|
|
171
|
-
].filter(Boolean).join("\n").replaceAll("\\", "/");
|
|
172
|
-
}, "internalRenderError");
|
|
173
|
-
const renderError = /* @__PURE__ */ __name((error, options = {}) => {
|
|
174
|
-
if (options.framesMaxLimit !== void 0 && options.framesMaxLimit <= 0) {
|
|
175
|
-
throw new RangeError("The 'framesMaxLimit' option must be a positive number");
|
|
176
|
-
}
|
|
177
|
-
return internalRenderError(error, options, 0);
|
|
178
|
-
}, "renderError");
|
|
179
|
-
|
|
180
|
-
export { renderError };
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const node_fs = require('node:fs');
|
|
6
|
-
const node_path = require('node:path');
|
|
7
|
-
const node_process = require('node:process');
|
|
8
|
-
const node_url = require('node:url');
|
|
9
|
-
const codeFrame_index = require('../code-frame/index.cjs');
|
|
10
|
-
const parseStacktrace = require('./parseStacktrace-woJgU2XY.cjs');
|
|
11
|
-
|
|
12
|
-
var __defProp = Object.defineProperty;
|
|
13
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
-
const getPrefix = /* @__PURE__ */ __name((prefix, indentation, deep) => {
|
|
15
|
-
if (deep === 0) {
|
|
16
|
-
return prefix.toString();
|
|
17
|
-
}
|
|
18
|
-
if (indentation === " ") {
|
|
19
|
-
return prefix + " ".repeat(deep);
|
|
20
|
-
}
|
|
21
|
-
return prefix + " ".repeat(indentation * deep);
|
|
22
|
-
}, "getPrefix");
|
|
23
|
-
const getRelativePath = /* @__PURE__ */ __name((filePath, cwdPath) => {
|
|
24
|
-
const path = filePath.replace("async file:", "file:");
|
|
25
|
-
return node_path.relative(cwdPath, path.startsWith("file:") ? node_url.fileURLToPath(path) : path);
|
|
26
|
-
}, "getRelativePath");
|
|
27
|
-
const getTitleText = /* @__PURE__ */ __name((error, hideErrorTitle, color) => {
|
|
28
|
-
if (hideErrorTitle) {
|
|
29
|
-
return color.title(error.message);
|
|
30
|
-
}
|
|
31
|
-
const messagePart = error.message ? `: ${error.message}` : "";
|
|
32
|
-
return color.title(error.name + messagePart);
|
|
33
|
-
}, "getTitleText");
|
|
34
|
-
const getMessage = /* @__PURE__ */ __name((error, { color, hideErrorTitle, indentation, prefix }, deep) => `${getPrefix(prefix, indentation, deep)}${getTitleText(error, hideErrorTitle, color)}
|
|
35
|
-
`, "getMessage");
|
|
36
|
-
const getHint = /* @__PURE__ */ __name((error, { color, indentation, prefix }, deep) => {
|
|
37
|
-
if (error.hint === void 0) {
|
|
38
|
-
return void 0;
|
|
39
|
-
}
|
|
40
|
-
const spaces = getPrefix(prefix, indentation, deep);
|
|
41
|
-
let message = "";
|
|
42
|
-
if (Array.isArray(error.hint)) {
|
|
43
|
-
for (const line of error.hint) {
|
|
44
|
-
message += `${(spaces + line).toString()}
|
|
45
|
-
`;
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
message += spaces + error.hint;
|
|
49
|
-
}
|
|
50
|
-
return color.hint(message);
|
|
51
|
-
}, "getHint");
|
|
52
|
-
const getMainFrame = /* @__PURE__ */ __name((trace, { color, cwd: cwdPath, displayShortPath, indentation, prefix }, deep = 0) => {
|
|
53
|
-
const filePath = displayShortPath ? getRelativePath(trace.file, cwdPath) : trace.file;
|
|
54
|
-
const { fileLine, method } = color;
|
|
55
|
-
return `${getPrefix(prefix, indentation, deep)}at ${trace.methodName ? `${method(trace.methodName)} ` : ""}${fileLine(filePath)}:${fileLine(
|
|
56
|
-
trace.line?.toString() ?? ""
|
|
57
|
-
)}`.toString();
|
|
58
|
-
}, "getMainFrame");
|
|
59
|
-
const getCode = /* @__PURE__ */ __name((trace, { color, indentation, linesAbove, linesBelow, prefix, showGutter, showLineNumbers, tabWidth }, deep) => {
|
|
60
|
-
if (trace.file === void 0) {
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
63
|
-
const filePath = trace.file.replace("file://", "");
|
|
64
|
-
if (!node_fs.existsSync(filePath)) {
|
|
65
|
-
return void 0;
|
|
66
|
-
}
|
|
67
|
-
const fileContent = node_fs.readFileSync(filePath, "utf8");
|
|
68
|
-
return codeFrame_index.codeFrame(
|
|
69
|
-
fileContent,
|
|
70
|
-
{
|
|
71
|
-
start: { column: trace.column, line: trace.line }
|
|
72
|
-
},
|
|
73
|
-
{ color, linesAbove, linesBelow, prefix: getPrefix(prefix, indentation, deep), showGutter, showLineNumbers, tabWidth }
|
|
74
|
-
);
|
|
75
|
-
}, "getCode");
|
|
76
|
-
const getErrors = /* @__PURE__ */ __name((error, options, deep) => {
|
|
77
|
-
if (error.errors.length === 0) {
|
|
78
|
-
return void 0;
|
|
79
|
-
}
|
|
80
|
-
let message = `${getPrefix(options.prefix, options.indentation, deep)}Errors:
|
|
81
|
-
|
|
82
|
-
`;
|
|
83
|
-
let first = true;
|
|
84
|
-
for (const error_ of error.errors) {
|
|
85
|
-
if (first) {
|
|
86
|
-
first = false;
|
|
87
|
-
} else {
|
|
88
|
-
message += "\n\n";
|
|
89
|
-
}
|
|
90
|
-
message += internalRenderError(error_, { ...options, framesMaxLimit: 1, hideErrorCodeView: options.hideErrorErrorsCodeView }, deep + 1);
|
|
91
|
-
}
|
|
92
|
-
return `
|
|
93
|
-
${message}`;
|
|
94
|
-
}, "getErrors");
|
|
95
|
-
const getCause = /* @__PURE__ */ __name((error, options, deep) => {
|
|
96
|
-
let message = `${getPrefix(options.prefix, options.indentation, deep)}Caused by:
|
|
97
|
-
|
|
98
|
-
`;
|
|
99
|
-
const cause = error.cause;
|
|
100
|
-
message += getMessage(cause, options, deep);
|
|
101
|
-
const stacktrace = parseStacktrace(cause);
|
|
102
|
-
const mainFrame = stacktrace.shift();
|
|
103
|
-
const hint = getHint(cause, options, deep);
|
|
104
|
-
if (hint) {
|
|
105
|
-
message += `${hint}
|
|
106
|
-
`;
|
|
107
|
-
}
|
|
108
|
-
if (mainFrame) {
|
|
109
|
-
message += getMainFrame(mainFrame, options, deep);
|
|
110
|
-
if (!options.hideErrorCauseCodeView) {
|
|
111
|
-
const code = getCode(mainFrame, options, deep);
|
|
112
|
-
if (code !== void 0) {
|
|
113
|
-
message += `
|
|
114
|
-
${code}`;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (cause.cause) {
|
|
119
|
-
message += `
|
|
120
|
-
${getCause(cause, options, deep + 1)}`;
|
|
121
|
-
} else if (cause instanceof AggregateError) {
|
|
122
|
-
const errors = getErrors(cause, options, deep);
|
|
123
|
-
if (errors !== void 0) {
|
|
124
|
-
message += `
|
|
125
|
-
${errors}`;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return `
|
|
129
|
-
${message}`;
|
|
130
|
-
}, "getCause");
|
|
131
|
-
const getStacktrace = /* @__PURE__ */ __name((stack, options) => (stack.length > 0 ? "\n" : "") + stack.map((frame) => getMainFrame(frame, options)).join("\n"), "getStacktrace");
|
|
132
|
-
const internalRenderError = /* @__PURE__ */ __name((error, options, deep) => {
|
|
133
|
-
const config = {
|
|
134
|
-
cwd: node_process.cwd(),
|
|
135
|
-
displayShortPath: false,
|
|
136
|
-
filterStacktrace: void 0,
|
|
137
|
-
framesMaxLimit: Number.POSITIVE_INFINITY,
|
|
138
|
-
hideErrorCauseCodeView: false,
|
|
139
|
-
hideErrorCodeView: false,
|
|
140
|
-
hideErrorErrorsCodeView: false,
|
|
141
|
-
hideErrorTitle: false,
|
|
142
|
-
hideMessage: false,
|
|
143
|
-
indentation: 4,
|
|
144
|
-
linesAbove: 2,
|
|
145
|
-
linesBelow: 3,
|
|
146
|
-
prefix: "",
|
|
147
|
-
showGutter: true,
|
|
148
|
-
showLineNumbers: true,
|
|
149
|
-
tabWidth: 4,
|
|
150
|
-
...options,
|
|
151
|
-
color: {
|
|
152
|
-
fileLine: /* @__PURE__ */ __name((value) => value, "fileLine"),
|
|
153
|
-
gutter: /* @__PURE__ */ __name((value) => value, "gutter"),
|
|
154
|
-
hint: /* @__PURE__ */ __name((value) => value, "hint"),
|
|
155
|
-
marker: /* @__PURE__ */ __name((value) => value, "marker"),
|
|
156
|
-
message: /* @__PURE__ */ __name((value) => value, "message"),
|
|
157
|
-
method: /* @__PURE__ */ __name((value) => value, "method"),
|
|
158
|
-
title: /* @__PURE__ */ __name((value) => value, "title"),
|
|
159
|
-
...options.color
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
const stack = parseStacktrace(error, {
|
|
163
|
-
filter: options.filterStacktrace,
|
|
164
|
-
frameLimit: config.framesMaxLimit
|
|
165
|
-
});
|
|
166
|
-
const mainFrame = stack.shift();
|
|
167
|
-
return [
|
|
168
|
-
options.hideMessage ? void 0 : getMessage(error, config, deep),
|
|
169
|
-
getHint(error, config, deep),
|
|
170
|
-
mainFrame ? getMainFrame(mainFrame, config, deep) : void 0,
|
|
171
|
-
mainFrame && !config.hideErrorCodeView ? getCode(mainFrame, config, deep) : void 0,
|
|
172
|
-
error instanceof AggregateError ? getErrors(error, config, deep) : void 0,
|
|
173
|
-
error.cause === void 0 ? void 0 : getCause(error, config, deep),
|
|
174
|
-
stack.length > 0 ? getStacktrace(stack, config) : void 0
|
|
175
|
-
].filter(Boolean).join("\n").replaceAll("\\", "/");
|
|
176
|
-
}, "internalRenderError");
|
|
177
|
-
const renderError = /* @__PURE__ */ __name((error, options = {}) => {
|
|
178
|
-
if (options.framesMaxLimit !== void 0 && options.framesMaxLimit <= 0) {
|
|
179
|
-
throw new RangeError("The 'framesMaxLimit' option must be a positive number");
|
|
180
|
-
}
|
|
181
|
-
return internalRenderError(error, options, 0);
|
|
182
|
-
}, "renderError");
|
|
183
|
-
|
|
184
|
-
exports.renderError = renderError;
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
const code = /* @__PURE__ */ __name((s) => `\`\`\`
|
|
4
|
-
${s.trim()}
|
|
5
|
-
\`\`\``, "code");
|
|
6
|
-
const bash = /* @__PURE__ */ __name((s) => `\`\`\`bash
|
|
7
|
-
${s.trim()}
|
|
8
|
-
\`\`\``, "bash");
|
|
9
|
-
const ts = /* @__PURE__ */ __name((s) => `\`\`\`ts
|
|
10
|
-
${s.trim()}
|
|
11
|
-
\`\`\``, "ts");
|
|
12
|
-
const js = /* @__PURE__ */ __name((s) => `\`\`\`js
|
|
13
|
-
${s.trim()}
|
|
14
|
-
\`\`\``, "js");
|
|
15
|
-
const has = /* @__PURE__ */ __name((message, ...needles) => {
|
|
16
|
-
const lower = message.toLowerCase();
|
|
17
|
-
return needles.some((n) => lower.includes(n.toLowerCase()));
|
|
18
|
-
}, "has");
|
|
19
|
-
const rules = [
|
|
20
|
-
{
|
|
21
|
-
name: "esm-cjs-interop",
|
|
22
|
-
test: /* @__PURE__ */ __name((error) => {
|
|
23
|
-
const message = (error?.message || String(error || "")).toString();
|
|
24
|
-
if (has(
|
|
25
|
-
message,
|
|
26
|
-
"err_require_esm",
|
|
27
|
-
"cannot use import statement outside a module",
|
|
28
|
-
"must use import to load es module",
|
|
29
|
-
"require() of es module",
|
|
30
|
-
"does not provide an export named"
|
|
31
|
-
)) {
|
|
32
|
-
return {
|
|
33
|
-
md: [
|
|
34
|
-
"Your project or a dependency may be mixing CommonJS and ES Modules.",
|
|
35
|
-
"",
|
|
36
|
-
"Try:",
|
|
37
|
-
"- Ensure package.json has the correct `type` (either `module` or `commonjs`).",
|
|
38
|
-
"- Use dynamic `import()` when requiring ESM from CJS.",
|
|
39
|
-
"- Prefer ESM-compatible entrypoints from dependencies.",
|
|
40
|
-
"- In Node, align `module` resolution with your bundler config.",
|
|
41
|
-
"",
|
|
42
|
-
"Check Node resolution:",
|
|
43
|
-
bash("node -v\ncat package.json | jq .type"),
|
|
44
|
-
"",
|
|
45
|
-
"Example dynamic import in CJS:",
|
|
46
|
-
js("(async () => { const mod = await import('some-esm'); mod.default(); })();")
|
|
47
|
-
].join("\n"),
|
|
48
|
-
title: "ESM/CJS interop"
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return void 0;
|
|
52
|
-
}, "test")
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "missing-default-export",
|
|
56
|
-
test: /* @__PURE__ */ __name((error) => {
|
|
57
|
-
const message = (error?.message || String(error || "")).toString();
|
|
58
|
-
if (has(message, "default export not found", "has no default export", "does not provide an export named 'default'", "is not exported from")) {
|
|
59
|
-
return {
|
|
60
|
-
md: [
|
|
61
|
-
"Verify your import/export shapes.",
|
|
62
|
-
"",
|
|
63
|
-
"Default export example:",
|
|
64
|
-
ts("export default function Component() {}\n// import Component from './file'"),
|
|
65
|
-
"",
|
|
66
|
-
"Named export example:",
|
|
67
|
-
ts("export function Component() {}\n// import { Component } from './file'")
|
|
68
|
-
].join("\n"),
|
|
69
|
-
title: "Export mismatch (default vs named)"
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return void 0;
|
|
73
|
-
}, "test")
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "port-in-use",
|
|
77
|
-
test: /* @__PURE__ */ __name((error) => {
|
|
78
|
-
const message = (error?.message || String(error || "")).toString();
|
|
79
|
-
if (has(message, "eaddrinuse", "address already in use", "listen eaddrinuse")) {
|
|
80
|
-
return {
|
|
81
|
-
md: [
|
|
82
|
-
"Another process is using the port.",
|
|
83
|
-
"",
|
|
84
|
-
"Change the port or stop the other process.",
|
|
85
|
-
"",
|
|
86
|
-
"On macOS/Linux:",
|
|
87
|
-
bash("lsof -i :3000\nkill -9 <PID>"),
|
|
88
|
-
"",
|
|
89
|
-
"On Windows (PowerShell):",
|
|
90
|
-
bash("netstat -ano | findstr :3000\ntaskkill /PID <PID> /F")
|
|
91
|
-
].join("\n"),
|
|
92
|
-
title: "Port already in use"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return void 0;
|
|
96
|
-
}, "test")
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: "file-not-found-or-case",
|
|
100
|
-
test: /* @__PURE__ */ __name((error, file) => {
|
|
101
|
-
const message = (error?.message || String(error || "")).toString();
|
|
102
|
-
if (has(message, "enoent", "module not found", "cannot find module")) {
|
|
103
|
-
return {
|
|
104
|
-
md: [
|
|
105
|
-
"Check the import path and filename case (Linux/macOS are case-sensitive).",
|
|
106
|
-
"If using TS path aliases, verify `tsconfig.paths` and bundler aliases.",
|
|
107
|
-
"",
|
|
108
|
-
"Current file:",
|
|
109
|
-
code(`${file.file}:${file.line}`)
|
|
110
|
-
].join("\n"),
|
|
111
|
-
title: "Missing file or path case mismatch"
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return void 0;
|
|
115
|
-
}, "test")
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: "ts-path-mapping",
|
|
119
|
-
test: /* @__PURE__ */ __name((error) => {
|
|
120
|
-
const message = (error?.message || String(error || "")).toString();
|
|
121
|
-
if (has(message, "ts2307", "cannot find module") || message.includes("TS2307")) {
|
|
122
|
-
return {
|
|
123
|
-
md: [
|
|
124
|
-
"If you use path aliases, align TS `paths` with Vite/Webpack resolve aliases.",
|
|
125
|
-
"Ensure file extensions are correct and included in resolver.",
|
|
126
|
-
"",
|
|
127
|
-
"tsconfig.json excerpt:",
|
|
128
|
-
ts(`{
|
|
129
|
-
"compilerOptions": {
|
|
130
|
-
"baseUrl": ".",
|
|
131
|
-
"paths": { "@/*": ["src/*"] }
|
|
132
|
-
}
|
|
133
|
-
}`)
|
|
134
|
-
].join("\n"),
|
|
135
|
-
title: "TypeScript path mapping / resolution"
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return void 0;
|
|
139
|
-
}, "test")
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
name: "network-dns-enotfound",
|
|
143
|
-
test: /* @__PURE__ */ __name((error) => {
|
|
144
|
-
const message = (error?.message || String(error || "")).toString();
|
|
145
|
-
if (has(message, "enotfound", "getaddrinfo enotfound", "dns", "fetch failed", "ecconnrefused", "econnrefused")) {
|
|
146
|
-
return {
|
|
147
|
-
md: [
|
|
148
|
-
"The host may be unreachable or misconfigured.",
|
|
149
|
-
"",
|
|
150
|
-
"Try:",
|
|
151
|
-
"- Verify the hostname and protocol (http/https).",
|
|
152
|
-
"- Check VPN/proxy and firewall.",
|
|
153
|
-
"- Confirm the service is running and listening on the expected port.",
|
|
154
|
-
"",
|
|
155
|
-
bash("ping <host>\nnslookup <host>\ncurl -v http://<host>:<port>")
|
|
156
|
-
].join("\n"),
|
|
157
|
-
title: "Network/DNS connection issue"
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
return void 0;
|
|
161
|
-
}, "test")
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
name: "react-hydration-mismatch",
|
|
165
|
-
test: /* @__PURE__ */ __name((error) => {
|
|
166
|
-
const message = (error?.message || String(error || "")).toString();
|
|
167
|
-
if (has(message, "hydration failed", "did not match", "expected server html", "text content does not match")) {
|
|
168
|
-
return {
|
|
169
|
-
md: [
|
|
170
|
-
"Client and server rendered markup differ.",
|
|
171
|
-
"",
|
|
172
|
-
"Checklist:",
|
|
173
|
-
"- Avoid non-deterministic rendering during SSR (dates, random, locale).",
|
|
174
|
-
"- Ensure feature flags / env checks are consistent between server and client.",
|
|
175
|
-
"- Wrap browser-only code with guards (e.g., check `typeof window !== 'undefined'`).",
|
|
176
|
-
"- Ensure data used on server matches client rehydration data."
|
|
177
|
-
].join("\n"),
|
|
178
|
-
title: "React hydration mismatch"
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
return void 0;
|
|
182
|
-
}, "test")
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
name: "undefined-property",
|
|
186
|
-
test: /* @__PURE__ */ __name((error) => {
|
|
187
|
-
const message = (error?.message || String(error || "")).toString();
|
|
188
|
-
if (has(message, "cannot read properties of undefined", "reading '")) {
|
|
189
|
-
return {
|
|
190
|
-
md: [
|
|
191
|
-
"A variable or function returned `undefined`.",
|
|
192
|
-
"",
|
|
193
|
-
"Mitigations:",
|
|
194
|
-
"- Add nullish checks before property access.",
|
|
195
|
-
"- Validate function return values and input props/state.",
|
|
196
|
-
"",
|
|
197
|
-
ts("const value = maybe?.prop; // or: if (maybe) { use(maybe.prop) }")
|
|
198
|
-
].join("\n"),
|
|
199
|
-
title: "Accessing property of undefined"
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
return void 0;
|
|
203
|
-
}, "test")
|
|
204
|
-
}
|
|
205
|
-
];
|
|
206
|
-
const ruleBasedFinder = {
|
|
207
|
-
handle: /* @__PURE__ */ __name(async (error, file) => {
|
|
208
|
-
try {
|
|
209
|
-
const matches = rules.map((r) => {
|
|
210
|
-
return { match: r.test(error, file), rule: r };
|
|
211
|
-
}).filter((x) => Boolean(x.match));
|
|
212
|
-
if (matches.length === 0) {
|
|
213
|
-
return void 0;
|
|
214
|
-
}
|
|
215
|
-
const sections = matches.toSorted((a, b) => (a.match.priority || 0) - (b.match.priority || 0)).map((m) => `#### ${m.match.title}
|
|
216
|
-
|
|
217
|
-
${m.match.md}`).join("\n\n---\n\n");
|
|
218
|
-
return { body: sections, header: "### Potential fixes detected" };
|
|
219
|
-
} catch {
|
|
220
|
-
return void 0;
|
|
221
|
-
}
|
|
222
|
-
}, "handle"),
|
|
223
|
-
name: "ruleBasedHints",
|
|
224
|
-
priority: 0
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
export { ruleBasedFinder as default };
|