@visulima/error 5.0.3 → 5.0.5
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 +31 -0
- package/dist/code-frame/get-marker-lines.d.ts +19 -0
- package/dist/code-frame/index-to-line-column.d.ts +7 -0
- package/dist/code-frame/index.d.ts +15 -7
- package/dist/code-frame/index.js +125 -6
- package/dist/{packem_shared/types-CrVmNoPV.d.ts → code-frame/types.d.ts} +4 -6
- package/dist/error/capture-raw-stack-trace.d.ts +2 -0
- package/dist/error/get-error-causes.d.ts +6 -0
- package/dist/error/index.d.ts +12 -96
- package/dist/error/index.js +8 -1
- package/dist/error/render/error.d.ts +22 -0
- package/dist/error/serialize/deserialize.d.ts +14 -0
- package/dist/error/serialize/error-constructors.d.ts +25 -0
- package/dist/error/serialize/error-proto.d.ts +10 -0
- package/dist/error/serialize/non-error.d.ts +7 -0
- package/dist/error/serialize/serialize.d.ts +14 -0
- package/dist/error/types.d.ts +33 -0
- package/dist/error/visulima-error.d.ts +16 -0
- package/dist/index.d.ts +12 -17
- package/dist/index.js +16 -1
- package/dist/packem_shared/NonError-D5FGLYKY.js +8 -0
- package/dist/packem_shared/addKnownErrorConstructor-s_3SsXtQ.js +30 -0
- package/dist/packem_shared/aiFinder-HftEgsry.js +277 -0
- package/dist/packem_shared/aiSolutionResponse-CJBMLS9t.js +34 -0
- package/dist/packem_shared/captureRawStackTrace-ySw7cU0U.js +10 -0
- package/dist/packem_shared/deserializeError-E0VQnnm0.js +116 -0
- package/dist/packem_shared/errorHintFinder-DEaeRnRW.js +21 -0
- package/dist/packem_shared/formatStackFrameLine-D3_6oSWZ.js +24 -0
- package/dist/packem_shared/getErrorCauses-DpUsmuqw.js +43 -0
- package/dist/packem_shared/index-y_UPkY2Z.js +9 -0
- package/dist/packem_shared/indexToLineColumn-Bg8UW1bU.js +50 -0
- package/dist/packem_shared/isVisulimaError-DA7QsCxH.js +34 -0
- package/dist/packem_shared/parseStacktrace-oQvk7wYp.js +273 -0
- package/dist/packem_shared/renderError-C30PRFtU.js +206 -0
- package/dist/packem_shared/ruleBasedFinder-C2F8rQ30.js +207 -0
- package/dist/packem_shared/serializeError-BZ62KiYZ.js +142 -0
- package/dist/solution/ai/ai-finder.d.ts +12 -0
- package/dist/solution/ai/ai-prompt.d.ts +2 -4
- package/dist/solution/ai/ai-prompt.js +13 -7
- package/dist/{packem_shared/ai-solution-response-BuaDQAEU.d.ts → solution/ai/ai-solution-response.d.ts} +1 -2
- package/dist/solution/ai/index.d.ts +3 -16
- package/dist/solution/ai/index.js +3 -1
- package/dist/solution/error-hint-finder.d.ts +3 -0
- package/dist/solution/index.d.ts +3 -8
- package/dist/solution/index.js +2 -1
- package/dist/solution/rule-based-finder.d.ts +3 -0
- package/dist/{packem_shared/types-BtQS7FHG.d.ts → solution/types.d.ts} +4 -6
- package/dist/stacktrace/index.d.ts +3 -26
- package/dist/stacktrace/index.js +2 -1
- package/dist/stacktrace/parse-stacktrace.d.ts +6 -0
- package/dist/stacktrace/stringify.d.ts +15 -0
- package/dist/stacktrace/types.d.ts +10 -0
- package/dist/util/normalize-lf.d.ts +2 -0
- package/dist/util/process.d.ts +5 -0
- package/package.json +1 -1
- package/dist/packem_shared/NonError-CS10kwil.js +0 -1
- package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.js +0 -1
- package/dist/packem_shared/aiFinder-DPoqj12B.js +0 -1
- package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.js +0 -10
- package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.js +0 -1
- package/dist/packem_shared/deserializeError-BJM8Kd6G.js +0 -1
- package/dist/packem_shared/errorHintFinder-C_g0nvml.js +0 -2
- package/dist/packem_shared/formatStackFrameLine-iU54KA81.js +0 -2
- package/dist/packem_shared/getErrorCauses-geeK5cwE.js +0 -1
- package/dist/packem_shared/index-CLFYRLyq.js +0 -1
- package/dist/packem_shared/indexToLineColumn-B1F7aNZh.js +0 -1
- package/dist/packem_shared/isVisulimaError-jVZgumOU.js +0 -1
- package/dist/packem_shared/parseStacktrace-Dnxnc4PL.js +0 -2
- package/dist/packem_shared/renderError-ZMlMvw1N.js +0 -18
- package/dist/packem_shared/ruleBasedFinder-P88d0gpK.js +0 -34
- package/dist/packem_shared/serializeError-CTpDr3CL.js +0 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
createHash
|
|
22
|
+
} = __cjs_getBuiltinModule("node:crypto");
|
|
23
|
+
const {
|
|
24
|
+
existsSync,
|
|
25
|
+
readFileSync,
|
|
26
|
+
mkdirSync,
|
|
27
|
+
writeFileSync
|
|
28
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
29
|
+
const {
|
|
30
|
+
tmpdir
|
|
31
|
+
} = __cjs_getBuiltinModule("node:os");
|
|
32
|
+
import { generateText } from 'ai';
|
|
33
|
+
import aiPrompt from '../solution/ai/ai-prompt.js';
|
|
34
|
+
import aiSolutionResponse from './aiSolutionResponse-CJBMLS9t.js';
|
|
35
|
+
|
|
36
|
+
const DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
|
|
37
|
+
const normalizeWindowsPath = (input = "") => {
|
|
38
|
+
if (!input) {
|
|
39
|
+
return input;
|
|
40
|
+
}
|
|
41
|
+
return input.replaceAll("\\", "/").replace(DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
42
|
+
};
|
|
43
|
+
const UNC_REGEX = /^[/\\]{2}/;
|
|
44
|
+
const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
|
|
45
|
+
const DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
46
|
+
const normalizeString = (path2, allowAboveRoot) => {
|
|
47
|
+
let result = "";
|
|
48
|
+
let lastSegmentLength = 0;
|
|
49
|
+
let lastSlash = -1;
|
|
50
|
+
let dots = 0;
|
|
51
|
+
let char;
|
|
52
|
+
for (let index = 0; index <= path2.length; ++index) {
|
|
53
|
+
if (index < path2.length) {
|
|
54
|
+
char = path2[index];
|
|
55
|
+
} else if (char === "/") {
|
|
56
|
+
break;
|
|
57
|
+
} else {
|
|
58
|
+
char = "/";
|
|
59
|
+
}
|
|
60
|
+
if (char === "/") {
|
|
61
|
+
if (lastSlash === index - 1 || dots === 1) ;
|
|
62
|
+
else if (dots === 2) {
|
|
63
|
+
if (result.length < 2 || lastSegmentLength !== 2 || !result.endsWith(".") || result.at(-2) !== ".") {
|
|
64
|
+
if (result.length > 2) {
|
|
65
|
+
const lastSlashIndex = result.lastIndexOf("/");
|
|
66
|
+
if (lastSlashIndex === -1) {
|
|
67
|
+
result = "";
|
|
68
|
+
lastSegmentLength = 0;
|
|
69
|
+
} else {
|
|
70
|
+
result = result.slice(0, lastSlashIndex);
|
|
71
|
+
lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
|
|
72
|
+
}
|
|
73
|
+
lastSlash = index;
|
|
74
|
+
dots = 0;
|
|
75
|
+
continue;
|
|
76
|
+
} else if (result.length > 0) {
|
|
77
|
+
result = "";
|
|
78
|
+
lastSegmentLength = 0;
|
|
79
|
+
lastSlash = index;
|
|
80
|
+
dots = 0;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (allowAboveRoot) {
|
|
85
|
+
result += result.length > 0 ? "/.." : "..";
|
|
86
|
+
lastSegmentLength = 2;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
if (result.length > 0) {
|
|
90
|
+
result += `/${path2.slice(lastSlash + 1, index)}`;
|
|
91
|
+
} else {
|
|
92
|
+
result = path2.slice(lastSlash + 1, index);
|
|
93
|
+
}
|
|
94
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
95
|
+
}
|
|
96
|
+
lastSlash = index;
|
|
97
|
+
dots = 0;
|
|
98
|
+
} else if (char === "." && dots !== -1) {
|
|
99
|
+
++dots;
|
|
100
|
+
} else {
|
|
101
|
+
dots = -1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
};
|
|
106
|
+
const isAbsolute = (path2) => IS_ABSOLUTE_RE.test(path2);
|
|
107
|
+
const normalize = function(path2) {
|
|
108
|
+
if (path2.length === 0) {
|
|
109
|
+
return ".";
|
|
110
|
+
}
|
|
111
|
+
path2 = normalizeWindowsPath(path2);
|
|
112
|
+
const isUNCPath = UNC_REGEX.exec(path2);
|
|
113
|
+
const isPathAbsolute = isAbsolute(path2);
|
|
114
|
+
const trailingSeparator = path2.at(-1) === "/";
|
|
115
|
+
path2 = normalizeString(path2, !isPathAbsolute);
|
|
116
|
+
if (path2.length === 0) {
|
|
117
|
+
if (isPathAbsolute) {
|
|
118
|
+
return "/";
|
|
119
|
+
}
|
|
120
|
+
return trailingSeparator ? "./" : ".";
|
|
121
|
+
}
|
|
122
|
+
if (trailingSeparator) {
|
|
123
|
+
path2 += "/";
|
|
124
|
+
}
|
|
125
|
+
if (DRIVE_LETTER_RE.test(path2)) {
|
|
126
|
+
path2 += "/";
|
|
127
|
+
}
|
|
128
|
+
if (isUNCPath) {
|
|
129
|
+
if (!isPathAbsolute) {
|
|
130
|
+
return `//./${path2}`;
|
|
131
|
+
}
|
|
132
|
+
return `//${path2}`;
|
|
133
|
+
}
|
|
134
|
+
return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
|
|
135
|
+
};
|
|
136
|
+
const join = (...segments) => {
|
|
137
|
+
let path2 = "";
|
|
138
|
+
for (const seg of segments) {
|
|
139
|
+
if (!seg) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (path2.length > 0) {
|
|
143
|
+
const pathTrailing = path2[path2.length - 1] === "/";
|
|
144
|
+
const segLeading = seg[0] === "/";
|
|
145
|
+
const both = pathTrailing && segLeading;
|
|
146
|
+
if (both) {
|
|
147
|
+
path2 += seg.slice(1);
|
|
148
|
+
} else {
|
|
149
|
+
path2 += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
path2 += seg;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return normalize(path2);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const DEFAULT_HEADER = "## Ai Generated Solution";
|
|
159
|
+
const DEFAULT_ERROR_MESSAGE = "Creation of a AI solution failed.";
|
|
160
|
+
const generateCacheKey = (error, file, temperature) => {
|
|
161
|
+
const keyData = {
|
|
162
|
+
error: {
|
|
163
|
+
message: error.message,
|
|
164
|
+
name: error.name,
|
|
165
|
+
stack: error.stack
|
|
166
|
+
},
|
|
167
|
+
file: {
|
|
168
|
+
file: file.file,
|
|
169
|
+
language: file.language,
|
|
170
|
+
line: file.line,
|
|
171
|
+
snippet: file.snippet
|
|
172
|
+
},
|
|
173
|
+
temperature
|
|
174
|
+
};
|
|
175
|
+
return createHash("sha256").update(JSON.stringify(keyData)).digest("hex");
|
|
176
|
+
};
|
|
177
|
+
const getCacheDirectory = (directory) => {
|
|
178
|
+
if (directory) {
|
|
179
|
+
return directory;
|
|
180
|
+
}
|
|
181
|
+
return join(tmpdir(), "visulima-error-cache");
|
|
182
|
+
};
|
|
183
|
+
const ensureCacheDirectory = (cacheDirectory) => {
|
|
184
|
+
if (!existsSync(cacheDirectory)) {
|
|
185
|
+
mkdirSync(cacheDirectory, { recursive: true });
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const getCacheFilePath = (cacheDirectory, key) => join(cacheDirectory, `${key}.json`);
|
|
189
|
+
const readFromCache = (cacheFilePath, ttl) => {
|
|
190
|
+
try {
|
|
191
|
+
if (!existsSync(cacheFilePath)) {
|
|
192
|
+
return void 0;
|
|
193
|
+
}
|
|
194
|
+
const cacheContent = readFileSync(cacheFilePath, "utf8");
|
|
195
|
+
const cacheEntry = JSON.parse(cacheContent);
|
|
196
|
+
const now = Date.now();
|
|
197
|
+
if (now - cacheEntry.timestamp > ttl) {
|
|
198
|
+
return void 0;
|
|
199
|
+
}
|
|
200
|
+
return cacheEntry.solution;
|
|
201
|
+
} catch {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const writeToCache = (cacheFilePath, solution, ttl) => {
|
|
206
|
+
try {
|
|
207
|
+
const cacheEntry = {
|
|
208
|
+
solution,
|
|
209
|
+
timestamp: Date.now(),
|
|
210
|
+
ttl
|
|
211
|
+
};
|
|
212
|
+
writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf8");
|
|
213
|
+
} catch {
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const aiFinder = (model, options) => {
|
|
217
|
+
return {
|
|
218
|
+
handle: async (error, file) => {
|
|
219
|
+
const cacheOptions = options?.cache;
|
|
220
|
+
const temperature = options?.temperature ?? 0;
|
|
221
|
+
const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
|
|
222
|
+
const cacheDirectory = getCacheDirectory(cacheOptions?.directory);
|
|
223
|
+
if (cacheOptions?.enabled !== false) {
|
|
224
|
+
const cacheKey = generateCacheKey(error, file, temperature);
|
|
225
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
226
|
+
const cachedSolution = readFromCache(cacheFilePath, ttl);
|
|
227
|
+
if (cachedSolution) {
|
|
228
|
+
return cachedSolution;
|
|
229
|
+
}
|
|
230
|
+
ensureCacheDirectory(cacheDirectory);
|
|
231
|
+
}
|
|
232
|
+
const content = aiPrompt({ applicationType: void 0, error, file });
|
|
233
|
+
try {
|
|
234
|
+
const result = await generateText({
|
|
235
|
+
model,
|
|
236
|
+
prompt: content,
|
|
237
|
+
temperature
|
|
238
|
+
});
|
|
239
|
+
const messageContent = result.text;
|
|
240
|
+
let solution;
|
|
241
|
+
if (messageContent) {
|
|
242
|
+
solution = {
|
|
243
|
+
body: aiSolutionResponse(messageContent),
|
|
244
|
+
header: DEFAULT_HEADER
|
|
245
|
+
};
|
|
246
|
+
} else {
|
|
247
|
+
solution = {
|
|
248
|
+
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
249
|
+
header: DEFAULT_HEADER
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (cacheOptions?.enabled !== false) {
|
|
253
|
+
const cacheKey = generateCacheKey(error, file, temperature);
|
|
254
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
255
|
+
writeToCache(cacheFilePath, solution, ttl);
|
|
256
|
+
}
|
|
257
|
+
return solution;
|
|
258
|
+
} catch (error_) {
|
|
259
|
+
console.error(error_);
|
|
260
|
+
const solution = {
|
|
261
|
+
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
262
|
+
header: DEFAULT_HEADER
|
|
263
|
+
};
|
|
264
|
+
if (cacheOptions?.enabled !== false) {
|
|
265
|
+
const cacheKey = generateCacheKey(error, file, temperature);
|
|
266
|
+
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
267
|
+
writeToCache(cacheFilePath, solution, ttl);
|
|
268
|
+
}
|
|
269
|
+
return solution;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
name: "AI SDK",
|
|
273
|
+
priority: 99
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export { aiFinder as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const between = (start, end, text) => {
|
|
2
|
+
const startPosition = text.indexOf(start);
|
|
3
|
+
if (startPosition === -1) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const adjustedStartPosition = startPosition + start.length;
|
|
7
|
+
const endPosition = text.indexOf(end, adjustedStartPosition);
|
|
8
|
+
if (endPosition === -1) {
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
return text.slice(adjustedStartPosition, endPosition).trim();
|
|
12
|
+
};
|
|
13
|
+
const aiSolutionResponse = (rawText) => {
|
|
14
|
+
const description = between("FIX", "ENDFIX", rawText);
|
|
15
|
+
if (!description) {
|
|
16
|
+
return [
|
|
17
|
+
"No solution found.",
|
|
18
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
19
|
+
`Provide this response to the Maintainer of <a href="https://github.com/visulima/visulima/issues/new?assignees=&labels=s%3A+pending+triage%2Cc%3A+bug&projects=&template=bug_report.yml" target="_blank" rel="noopener noreferrer" class="text-blue-500 hover:underline inline-flex items-center text-sm">@visulima/error</a>.`,
|
|
20
|
+
`"${rawText}"`
|
|
21
|
+
].join("</br></br>");
|
|
22
|
+
}
|
|
23
|
+
const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
|
|
24
|
+
return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
|
|
25
|
+
|
|
26
|
+
## Links
|
|
27
|
+
|
|
28
|
+
${links.map((link) => `- <a href="${link.url}" target="_blank" rel="noopener noreferrer">${link.title}</a>`).join("\n")}
|
|
29
|
+
|
|
30
|
+
--------------------
|
|
31
|
+
This solution was generated with the <a href="https://sdk.vercel.ai/" target="_blank" rel="noopener noreferrer">AI SDK</a> and may not be 100% accurate.`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { aiSolutionResponse as default };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { i as isPlainObject } from './index-y_UPkY2Z.js';
|
|
2
|
+
import { isErrorLike, getErrorConstructor } from './addKnownErrorConstructor-s_3SsXtQ.js';
|
|
3
|
+
import NonError from './NonError-D5FGLYKY.js';
|
|
4
|
+
|
|
5
|
+
const defaultOptions = {
|
|
6
|
+
maxDepth: Number.POSITIVE_INFINITY
|
|
7
|
+
};
|
|
8
|
+
const deserializePlainObject = (object, options, depth = 0) => {
|
|
9
|
+
if (isErrorLike(object)) {
|
|
10
|
+
return reconstructError(object, options, depth);
|
|
11
|
+
}
|
|
12
|
+
if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
|
|
13
|
+
return new NonError(JSON.stringify(object));
|
|
14
|
+
}
|
|
15
|
+
return new NonError(JSON.stringify(object));
|
|
16
|
+
};
|
|
17
|
+
const reconstructAggregateError = (Constructor, errors, message, options, depth) => {
|
|
18
|
+
const reconstructedErrors = errors.map((error_) => deserializeValue(error_, options, depth + 1));
|
|
19
|
+
return new Constructor(reconstructedErrors, message);
|
|
20
|
+
};
|
|
21
|
+
const reconstructError = (serialized, options, depth) => {
|
|
22
|
+
if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
|
|
23
|
+
return new NonError(JSON.stringify(serialized));
|
|
24
|
+
}
|
|
25
|
+
const { cause, errors, message, name, stack, ...properties } = serialized;
|
|
26
|
+
const Constructor = getErrorConstructor(name) || Error;
|
|
27
|
+
const error = name === "AggregateError" && Array.isArray(errors) ? reconstructAggregateError(Constructor, errors, message, options, depth) : new Constructor(message);
|
|
28
|
+
if (!error.name && name) {
|
|
29
|
+
error.name = name;
|
|
30
|
+
}
|
|
31
|
+
if (message !== void 0) {
|
|
32
|
+
error.message = message;
|
|
33
|
+
}
|
|
34
|
+
if (stack) {
|
|
35
|
+
error.stack = stack;
|
|
36
|
+
}
|
|
37
|
+
restoreErrorProperties(error, properties, cause, name, options, depth);
|
|
38
|
+
if (cause !== void 0) {
|
|
39
|
+
error.cause = deserializeValue(cause, options, depth + 1);
|
|
40
|
+
}
|
|
41
|
+
makePropertiesEnumerable(error, serialized);
|
|
42
|
+
return error;
|
|
43
|
+
};
|
|
44
|
+
const deserializeValue = (value, options, depth) => {
|
|
45
|
+
if (isPlainObject(value)) {
|
|
46
|
+
return deserializePlainObject(value, options, depth);
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
return value.map((item) => deserializeValue(item, options, depth));
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
const restoreErrorProperties = (error, properties, cause, name, options, depth) => {
|
|
54
|
+
const errorCopy = error;
|
|
55
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
56
|
+
if (key === "cause" && cause !== void 0) {
|
|
57
|
+
continue;
|
|
58
|
+
} else if (key === "errors" && name === "AggregateError") {
|
|
59
|
+
continue;
|
|
60
|
+
} else {
|
|
61
|
+
errorCopy[key] = deserializeValue(value, options, depth + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const makePropertiesEnumerable = (error, serialized) => {
|
|
66
|
+
const errorProperties = /* @__PURE__ */ new Set();
|
|
67
|
+
errorProperties.add("name");
|
|
68
|
+
errorProperties.add("message");
|
|
69
|
+
errorProperties.add("stack");
|
|
70
|
+
for (const key of Object.keys(serialized)) {
|
|
71
|
+
errorProperties.add(key);
|
|
72
|
+
}
|
|
73
|
+
for (const key of errorProperties) {
|
|
74
|
+
if (key in error) {
|
|
75
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
76
|
+
if (descriptor && !descriptor.enumerable) {
|
|
77
|
+
Object.defineProperty(error, key, {
|
|
78
|
+
...descriptor,
|
|
79
|
+
enumerable: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const handlePrimitive = (value) => new NonError(JSON.stringify(value));
|
|
86
|
+
const handleArray = (value) => new NonError(JSON.stringify(value));
|
|
87
|
+
const handlePlainObject = (value, config) => {
|
|
88
|
+
if (isErrorLike(value)) {
|
|
89
|
+
return reconstructError(value, config, 0);
|
|
90
|
+
}
|
|
91
|
+
return deserializePlainObject(value, config);
|
|
92
|
+
};
|
|
93
|
+
const deserialize = (value, options = {}) => {
|
|
94
|
+
const config = { ...defaultOptions, ...options };
|
|
95
|
+
if (value instanceof Error) {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
if (value === null) {
|
|
99
|
+
return handlePrimitive(null);
|
|
100
|
+
}
|
|
101
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
102
|
+
return handlePrimitive(value);
|
|
103
|
+
}
|
|
104
|
+
if (Array.isArray(value)) {
|
|
105
|
+
return handleArray(value);
|
|
106
|
+
}
|
|
107
|
+
if (isErrorLike(value)) {
|
|
108
|
+
return reconstructError(value, config, 0);
|
|
109
|
+
}
|
|
110
|
+
if (isPlainObject(value)) {
|
|
111
|
+
return handlePlainObject(value, config);
|
|
112
|
+
}
|
|
113
|
+
return new NonError(JSON.stringify(value));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export { deserialize as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const errorHintFinder = {
|
|
2
|
+
handle: async (error) => {
|
|
3
|
+
if (error.hint === void 0 || error.hint === null) {
|
|
4
|
+
return void 0;
|
|
5
|
+
}
|
|
6
|
+
if (typeof error.hint === "string" && error.hint !== "") {
|
|
7
|
+
return { body: error.hint };
|
|
8
|
+
}
|
|
9
|
+
if (typeof error.hint === "object" && typeof error.hint.body === "string") {
|
|
10
|
+
return error.hint;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(error.hint)) {
|
|
13
|
+
return { body: error.hint.join("\n") };
|
|
14
|
+
}
|
|
15
|
+
return void 0;
|
|
16
|
+
},
|
|
17
|
+
name: "errorHint",
|
|
18
|
+
priority: 1
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { errorHintFinder as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const formatStackFrameLine = (frame) => {
|
|
2
|
+
const method = frame.methodName && frame.methodName !== "<unknown>" ? `${frame.methodName} ` : "";
|
|
3
|
+
const file = frame.file ?? "<unknown>";
|
|
4
|
+
const line = frame.line ?? 0;
|
|
5
|
+
const column = frame.column ?? 0;
|
|
6
|
+
if (method.trim()) {
|
|
7
|
+
return ` at ${method}(${file}:${line}:${column})`;
|
|
8
|
+
}
|
|
9
|
+
return ` at ${file}:${line}:${column}`;
|
|
10
|
+
};
|
|
11
|
+
const formatStacktrace = (frames, options) => {
|
|
12
|
+
const lines = [];
|
|
13
|
+
if (options?.header && (options.header.name || options.header.message)) {
|
|
14
|
+
const headerName = String(options.header.name || "Error");
|
|
15
|
+
const headerMessage = String(options.header.message || "");
|
|
16
|
+
lines.push(`${headerName}${headerMessage ? ": " : ""}${headerMessage}`);
|
|
17
|
+
}
|
|
18
|
+
for (const frame of frames) {
|
|
19
|
+
lines.push(formatStackFrameLine(frame));
|
|
20
|
+
}
|
|
21
|
+
return lines.join("\n");
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { formatStackFrameLine, formatStacktrace };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
inspect
|
|
22
|
+
} = __cjs_getBuiltinModule("node:util");
|
|
23
|
+
|
|
24
|
+
const getErrorCauses = (error) => {
|
|
25
|
+
const seen = /* @__PURE__ */ new Set();
|
|
26
|
+
const causes = [];
|
|
27
|
+
let currentError = error;
|
|
28
|
+
while (currentError) {
|
|
29
|
+
if (seen.has(currentError)) {
|
|
30
|
+
console.error(`Circular reference detected in error causes: ${inspect(error)}`);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
causes.push(currentError);
|
|
34
|
+
seen.add(currentError);
|
|
35
|
+
if (!currentError.cause) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
currentError = currentError.cause;
|
|
39
|
+
}
|
|
40
|
+
return causes;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { getErrorCauses as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function isPlainObject(value) {
|
|
2
|
+
if (typeof value !== "object" || value === null) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const prototype = Object.getPrototypeOf(value);
|
|
6
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { isPlainObject as i };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const binarySearch = (element, array) => {
|
|
2
|
+
let m = 0;
|
|
3
|
+
let n = array.length - 2;
|
|
4
|
+
while (m < n) {
|
|
5
|
+
const key = m + (n - m >> 1);
|
|
6
|
+
if (element < array[key]) {
|
|
7
|
+
n = key - 1;
|
|
8
|
+
} else if (element >= array[key + 1]) {
|
|
9
|
+
m = key + 1;
|
|
10
|
+
} else {
|
|
11
|
+
m = key;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return m;
|
|
16
|
+
};
|
|
17
|
+
const getLineStartIndexes = (string_) => (
|
|
18
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
19
|
+
string_.split(/\n|\r(?!\n)/).reduce(
|
|
20
|
+
(accumulator, current) => {
|
|
21
|
+
accumulator.push(accumulator.at(-1) + current.length + 1);
|
|
22
|
+
return accumulator;
|
|
23
|
+
},
|
|
24
|
+
[0]
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
const indexToLineColumn = (input, index, options) => {
|
|
28
|
+
const skipChecks = options?.skipChecks ?? false;
|
|
29
|
+
if (!skipChecks && (!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
|
|
30
|
+
return { column: 0, line: 0 };
|
|
31
|
+
}
|
|
32
|
+
if (!skipChecks && (typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
|
|
33
|
+
return { column: 0, line: 0 };
|
|
34
|
+
}
|
|
35
|
+
if (typeof input === "string") {
|
|
36
|
+
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
37
|
+
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
38
|
+
return {
|
|
39
|
+
column: index - startIndexesOfEachLine[line2] + 1,
|
|
40
|
+
line: line2 + 1
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const line = binarySearch(index, input);
|
|
44
|
+
return {
|
|
45
|
+
column: index - input[line] + 1,
|
|
46
|
+
line: line + 1
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { indexToLineColumn as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const isVisulimaError = (error) => error instanceof Error && error.type === "VisulimaError";
|
|
2
|
+
class VisulimaError extends Error {
|
|
3
|
+
loc;
|
|
4
|
+
title;
|
|
5
|
+
/**
|
|
6
|
+
* A message that explains to the user how they can fix the error.
|
|
7
|
+
*/
|
|
8
|
+
hint;
|
|
9
|
+
type = "VisulimaError";
|
|
10
|
+
constructor({ cause, hint, location, message, name, stack, title }) {
|
|
11
|
+
super(message, {
|
|
12
|
+
cause
|
|
13
|
+
});
|
|
14
|
+
this.title = title;
|
|
15
|
+
this.name = name;
|
|
16
|
+
this.stack = stack ?? this.stack;
|
|
17
|
+
this.loc = location;
|
|
18
|
+
this.hint = hint;
|
|
19
|
+
}
|
|
20
|
+
setLocation(location) {
|
|
21
|
+
this.loc = location;
|
|
22
|
+
}
|
|
23
|
+
setName(name) {
|
|
24
|
+
this.name = name;
|
|
25
|
+
}
|
|
26
|
+
setMessage(message) {
|
|
27
|
+
this.message = message;
|
|
28
|
+
}
|
|
29
|
+
setHint(hint) {
|
|
30
|
+
this.hint = hint;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { VisulimaError, isVisulimaError };
|