@visulima/error 4.4.18 → 4.6.0

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 (70) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE.md +125 -0
  3. package/README.md +262 -0
  4. package/dist/code-frame/index.cjs +6 -5
  5. package/dist/code-frame/index.mjs +6 -5
  6. package/dist/error/index.cjs +10 -3
  7. package/dist/error/index.d.cts +19 -1
  8. package/dist/error/index.d.mts +19 -1
  9. package/dist/error/index.d.ts +19 -1
  10. package/dist/error/index.mjs +6 -3
  11. package/dist/index.cjs +23 -5
  12. package/dist/index.d.cts +6 -2
  13. package/dist/index.d.mts +6 -2
  14. package/dist/index.d.ts +6 -2
  15. package/dist/index.mjs +13 -5
  16. package/dist/packem_shared/NonError-BrwMc2LE.mjs +13 -0
  17. package/dist/packem_shared/NonError-DqwGL5Cy.cjs +15 -0
  18. package/dist/packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs +32 -0
  19. package/dist/packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs +39 -0
  20. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.cts +3 -0
  21. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.mts +3 -0
  22. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.ts +3 -0
  23. package/dist/packem_shared/aiFinder-BR9Pq804.cjs +259 -0
  24. package/dist/packem_shared/aiFinder-CFHvOjD8.mjs +257 -0
  25. package/dist/packem_shared/aiSolutionResponse-BaN1M990.mjs +36 -0
  26. package/dist/packem_shared/aiSolutionResponse-Cqi0mFxy.cjs +38 -0
  27. package/dist/packem_shared/deserializeError-Be3qOGBQ.cjs +120 -0
  28. package/dist/packem_shared/deserializeError-DuzHucBb.mjs +118 -0
  29. package/dist/packem_shared/errorHintFinder-CQy_qIK3.mjs +23 -0
  30. package/dist/packem_shared/errorHintFinder-DZugFHq0.cjs +25 -0
  31. package/dist/packem_shared/formatStackFrameLine-DcXSX--m.cjs +31 -0
  32. package/dist/packem_shared/formatStackFrameLine-DqkmKWH3.mjs +26 -0
  33. package/dist/packem_shared/index-BmoOJLvu.mjs +12 -0
  34. package/dist/packem_shared/index-C53Tqb7g.cjs +14 -0
  35. package/dist/packem_shared/{indexToLineColumn-Dx91YDU1.mjs → indexToLineColumn-CKQKtKEK.mjs} +0 -2
  36. package/dist/packem_shared/{indexToLineColumn-DjmjeiIY.cjs → indexToLineColumn-Cro5eT8v.cjs} +0 -2
  37. package/dist/packem_shared/{isVisulimaError-BVLWvREw.cjs → isVisulimaError-Bb1_TB6w.cjs} +0 -1
  38. package/dist/packem_shared/{isVisulimaError-H6TqEA42.mjs → isVisulimaError-zyd80Gui.mjs} +0 -1
  39. package/dist/packem_shared/{parseStacktrace-BKGoWCwC.mjs → parseStacktrace-BlguTUcF.mjs} +10 -15
  40. package/dist/packem_shared/{parseStacktrace-6pFoXW43.cjs → parseStacktrace-woJgU2XY.cjs} +10 -15
  41. package/dist/packem_shared/{renderError-BWpM2m6k.mjs → renderError-Cn8M0fQ3.mjs} +37 -22
  42. package/dist/packem_shared/{renderError-CXZTAXig.cjs → renderError-n3kXGdYj.cjs} +35 -20
  43. package/dist/packem_shared/ruleBasedFinder-Cbmc6N7f.mjs +227 -0
  44. package/dist/packem_shared/ruleBasedFinder-CkybTSHw.cjs +229 -0
  45. package/dist/packem_shared/{serializeError-DusTUACt.mjs → serializeError-DHIelq5o.mjs} +2 -11
  46. package/dist/packem_shared/{serializeError-CT7s0Ffk.cjs → serializeError-Dt7oFM2R.cjs} +3 -12
  47. package/dist/packem_shared/types-BtQS7FHG.d.cts +20 -0
  48. package/dist/packem_shared/types-BtQS7FHG.d.mts +20 -0
  49. package/dist/packem_shared/types-BtQS7FHG.d.ts +20 -0
  50. package/dist/solution/ai/ai-prompt.cjs +42 -0
  51. package/dist/solution/ai/ai-prompt.d.cts +9 -0
  52. package/dist/solution/ai/ai-prompt.d.mts +9 -0
  53. package/dist/solution/ai/ai-prompt.d.ts +9 -0
  54. package/dist/solution/ai/ai-prompt.mjs +40 -0
  55. package/dist/solution/ai/index.cjs +13 -0
  56. package/dist/solution/ai/index.d.cts +16 -0
  57. package/dist/solution/ai/index.d.mts +16 -0
  58. package/dist/solution/ai/index.d.ts +16 -0
  59. package/dist/solution/ai/index.mjs +3 -0
  60. package/dist/solution/index.cjs +11 -0
  61. package/dist/solution/index.d.cts +8 -0
  62. package/dist/solution/index.d.mts +8 -0
  63. package/dist/solution/index.d.ts +8 -0
  64. package/dist/solution/index.mjs +2 -0
  65. package/dist/stacktrace/index.cjs +4 -1
  66. package/dist/stacktrace/index.d.cts +10 -2
  67. package/dist/stacktrace/index.d.mts +10 -2
  68. package/dist/stacktrace/index.d.ts +10 -2
  69. package/dist/stacktrace/index.mjs +2 -1
  70. package/package.json +63 -16
@@ -0,0 +1,257 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { generateText } from 'ai';
5
+ import aiPrompt from '../solution/ai/ai-prompt.mjs';
6
+ import aiSolutionResponse from './aiSolutionResponse-BaN1M990.mjs';
7
+
8
+ var __defProp$1 = Object.defineProperty;
9
+ var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
10
+ var __defProp$1$1 = Object.defineProperty;
11
+ var __name$1$1 = /* @__PURE__ */ __name$1((target, value) => __defProp$1$1(target, "name", { value, configurable: true }), "__name$1");
12
+ const DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
13
+ const normalizeWindowsPath = /* @__PURE__ */ __name$1$1((input = "") => {
14
+ if (!input) {
15
+ return input;
16
+ }
17
+ return input.replaceAll("\\", "/").replace(DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
18
+ }, "normalizeWindowsPath");
19
+ var __defProp2 = Object.defineProperty;
20
+ var __name2 = /* @__PURE__ */ __name$1((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
21
+ const UNC_REGEX = /^[/\\]{2}/;
22
+ const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
23
+ const DRIVE_LETTER_RE = /^[A-Z]:$/i;
24
+ const normalizeString = /* @__PURE__ */ __name2((path2, allowAboveRoot) => {
25
+ let result = "";
26
+ let lastSegmentLength = 0;
27
+ let lastSlash = -1;
28
+ let dots = 0;
29
+ let char = null;
30
+ for (let index = 0; index <= path2.length; ++index) {
31
+ if (index < path2.length) {
32
+ char = path2[index];
33
+ } else if (char === "/") {
34
+ break;
35
+ } else {
36
+ char = "/";
37
+ }
38
+ if (char === "/") {
39
+ if (lastSlash === index - 1 || dots === 1) ;
40
+ else if (dots === 2) {
41
+ if (result.length < 2 || lastSegmentLength !== 2 || !result.endsWith(".") || result.at(-2) !== ".") {
42
+ if (result.length > 2) {
43
+ const lastSlashIndex = result.lastIndexOf("/");
44
+ if (lastSlashIndex === -1) {
45
+ result = "";
46
+ lastSegmentLength = 0;
47
+ } else {
48
+ result = result.slice(0, lastSlashIndex);
49
+ lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
50
+ }
51
+ lastSlash = index;
52
+ dots = 0;
53
+ continue;
54
+ } else if (result.length > 0) {
55
+ result = "";
56
+ lastSegmentLength = 0;
57
+ lastSlash = index;
58
+ dots = 0;
59
+ continue;
60
+ }
61
+ }
62
+ if (allowAboveRoot) {
63
+ result += result.length > 0 ? "/.." : "..";
64
+ lastSegmentLength = 2;
65
+ }
66
+ } else {
67
+ if (result.length > 0) {
68
+ result += `/${path2.slice(lastSlash + 1, index)}`;
69
+ } else {
70
+ result = path2.slice(lastSlash + 1, index);
71
+ }
72
+ lastSegmentLength = index - lastSlash - 1;
73
+ }
74
+ lastSlash = index;
75
+ dots = 0;
76
+ } else if (char === "." && dots !== -1) {
77
+ ++dots;
78
+ } else {
79
+ dots = -1;
80
+ }
81
+ }
82
+ return result;
83
+ }, "normalizeString");
84
+ const isAbsolute = /* @__PURE__ */ __name2((path2) => IS_ABSOLUTE_RE.test(path2), "isAbsolute");
85
+ const normalize = /* @__PURE__ */ __name2(function(path2) {
86
+ if (path2.length === 0) {
87
+ return ".";
88
+ }
89
+ path2 = normalizeWindowsPath(path2);
90
+ const isUNCPath = UNC_REGEX.exec(path2);
91
+ const isPathAbsolute = isAbsolute(path2);
92
+ const trailingSeparator = path2.at(-1) === "/";
93
+ path2 = normalizeString(path2, !isPathAbsolute);
94
+ if (path2.length === 0) {
95
+ if (isPathAbsolute) {
96
+ return "/";
97
+ }
98
+ return trailingSeparator ? "./" : ".";
99
+ }
100
+ if (trailingSeparator) {
101
+ path2 += "/";
102
+ }
103
+ if (DRIVE_LETTER_RE.test(path2)) {
104
+ path2 += "/";
105
+ }
106
+ if (isUNCPath) {
107
+ if (!isPathAbsolute) {
108
+ return `//./${path2}`;
109
+ }
110
+ return `//${path2}`;
111
+ }
112
+ return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
113
+ }, "normalize");
114
+ const join = /* @__PURE__ */ __name2((...segments) => {
115
+ let path2 = "";
116
+ for (const seg of segments) {
117
+ if (!seg) {
118
+ continue;
119
+ }
120
+ if (path2.length > 0) {
121
+ const pathTrailing = path2[path2.length - 1] === "/";
122
+ const segLeading = seg[0] === "/";
123
+ const both = pathTrailing && segLeading;
124
+ if (both) {
125
+ path2 += seg.slice(1);
126
+ } else {
127
+ path2 += pathTrailing || segLeading ? seg : `/${seg}`;
128
+ }
129
+ } else {
130
+ path2 += seg;
131
+ }
132
+ }
133
+ return normalize(path2);
134
+ }, "join");
135
+
136
+ var __defProp = Object.defineProperty;
137
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
138
+ const DEFAULT_HEADER = "## Ai Generated Solution";
139
+ const DEFAULT_ERROR_MESSAGE = "Creation of a AI solution failed.";
140
+ const generateCacheKey = /* @__PURE__ */ __name((error, file, temperature) => {
141
+ const keyData = {
142
+ error: {
143
+ message: error.message,
144
+ name: error.name,
145
+ stack: error.stack
146
+ },
147
+ file: {
148
+ file: file.file,
149
+ language: file.language,
150
+ line: file.line,
151
+ snippet: file.snippet
152
+ },
153
+ temperature
154
+ };
155
+ return createHash("sha256").update(JSON.stringify(keyData)).digest("hex");
156
+ }, "generateCacheKey");
157
+ const getCacheDirectory = /* @__PURE__ */ __name((directory) => {
158
+ if (directory) {
159
+ return directory;
160
+ }
161
+ return join(tmpdir(), "visulima-error-cache");
162
+ }, "getCacheDirectory");
163
+ const ensureCacheDirectory = /* @__PURE__ */ __name((cacheDirectory) => {
164
+ if (!existsSync(cacheDirectory)) {
165
+ mkdirSync(cacheDirectory, { recursive: true });
166
+ }
167
+ }, "ensureCacheDirectory");
168
+ const getCacheFilePath = /* @__PURE__ */ __name((cacheDirectory, key) => join(cacheDirectory, `${key}.json`), "getCacheFilePath");
169
+ const readFromCache = /* @__PURE__ */ __name((cacheFilePath, ttl) => {
170
+ try {
171
+ if (!existsSync(cacheFilePath)) {
172
+ return void 0;
173
+ }
174
+ const cacheContent = readFileSync(cacheFilePath, "utf8");
175
+ const cacheEntry = JSON.parse(cacheContent);
176
+ const now = Date.now();
177
+ if (now - cacheEntry.timestamp > ttl) {
178
+ return void 0;
179
+ }
180
+ return cacheEntry.solution;
181
+ } catch {
182
+ return void 0;
183
+ }
184
+ }, "readFromCache");
185
+ const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
186
+ try {
187
+ const cacheEntry = {
188
+ solution,
189
+ timestamp: Date.now(),
190
+ ttl
191
+ };
192
+ writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf8");
193
+ } catch {
194
+ }
195
+ }, "writeToCache");
196
+ const aiFinder = /* @__PURE__ */ __name((model, options) => {
197
+ return {
198
+ handle: /* @__PURE__ */ __name(async (error, file) => {
199
+ const cacheOptions = options?.cache;
200
+ const temperature = options?.temperature ?? 0;
201
+ const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
202
+ const cacheDirectory = getCacheDirectory(cacheOptions?.directory);
203
+ if (cacheOptions?.enabled !== false) {
204
+ const cacheKey = generateCacheKey(error, file, temperature);
205
+ const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
206
+ const cachedSolution = readFromCache(cacheFilePath, ttl);
207
+ if (cachedSolution) {
208
+ return cachedSolution;
209
+ }
210
+ ensureCacheDirectory(cacheDirectory);
211
+ }
212
+ const content = aiPrompt({ applicationType: void 0, error, file });
213
+ try {
214
+ const result = await generateText({
215
+ model,
216
+ prompt: content,
217
+ temperature
218
+ });
219
+ const messageContent = result.text;
220
+ let solution;
221
+ if (messageContent) {
222
+ solution = {
223
+ body: aiSolutionResponse(messageContent),
224
+ header: DEFAULT_HEADER
225
+ };
226
+ } else {
227
+ solution = {
228
+ body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
229
+ header: DEFAULT_HEADER
230
+ };
231
+ }
232
+ if (cacheOptions?.enabled !== false) {
233
+ const cacheKey = generateCacheKey(error, file, temperature);
234
+ const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
235
+ writeToCache(cacheFilePath, solution, ttl);
236
+ }
237
+ return solution;
238
+ } catch (error_) {
239
+ console.error(error_);
240
+ const solution = {
241
+ body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
242
+ header: DEFAULT_HEADER
243
+ };
244
+ if (cacheOptions?.enabled !== false) {
245
+ const cacheKey = generateCacheKey(error, file, temperature);
246
+ const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
247
+ writeToCache(cacheFilePath, solution, ttl);
248
+ }
249
+ return solution;
250
+ }
251
+ }, "handle"),
252
+ name: "AI SDK",
253
+ priority: 99
254
+ };
255
+ }, "aiFinder");
256
+
257
+ export { aiFinder as default };
@@ -0,0 +1,36 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const between = /* @__PURE__ */ __name((start, end, text) => {
4
+ const startPosition = text.indexOf(start);
5
+ if (startPosition === -1) {
6
+ return "";
7
+ }
8
+ const adjustedStartPosition = startPosition + start.length;
9
+ const endPosition = text.indexOf(end, adjustedStartPosition);
10
+ if (endPosition === -1) {
11
+ return "";
12
+ }
13
+ return text.slice(adjustedStartPosition, endPosition).trim();
14
+ }, "between");
15
+ const aiSolutionResponse = /* @__PURE__ */ __name((rawText) => {
16
+ const description = between("FIX", "ENDFIX", rawText);
17
+ if (!description) {
18
+ return [
19
+ "No solution found.",
20
+ // eslint-disable-next-line no-secrets/no-secrets
21
+ `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>.`,
22
+ `"${rawText}"`
23
+ ].join("</br></br>");
24
+ }
25
+ const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
26
+ return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
27
+
28
+ ## Links
29
+
30
+ ${links.map((link) => `- <a href="${link.url}" target="_blank" rel="noopener noreferrer">${link.title}</a>`).join("\n")}
31
+
32
+ --------------------
33
+ 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.`;
34
+ }, "aiSolutionResponse");
35
+
36
+ export { aiSolutionResponse as default };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ const between = /* @__PURE__ */ __name((start, end, text) => {
6
+ const startPosition = text.indexOf(start);
7
+ if (startPosition === -1) {
8
+ return "";
9
+ }
10
+ const adjustedStartPosition = startPosition + start.length;
11
+ const endPosition = text.indexOf(end, adjustedStartPosition);
12
+ if (endPosition === -1) {
13
+ return "";
14
+ }
15
+ return text.slice(adjustedStartPosition, endPosition).trim();
16
+ }, "between");
17
+ const aiSolutionResponse = /* @__PURE__ */ __name((rawText) => {
18
+ const description = between("FIX", "ENDFIX", rawText);
19
+ if (!description) {
20
+ return [
21
+ "No solution found.",
22
+ // eslint-disable-next-line no-secrets/no-secrets
23
+ `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>.`,
24
+ `"${rawText}"`
25
+ ].join("</br></br>");
26
+ }
27
+ const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
28
+ return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
29
+
30
+ ## Links
31
+
32
+ ${links.map((link) => `- <a href="${link.url}" target="_blank" rel="noopener noreferrer">${link.title}</a>`).join("\n")}
33
+
34
+ --------------------
35
+ 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.`;
36
+ }, "aiSolutionResponse");
37
+
38
+ module.exports = aiSolutionResponse;
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index-C53Tqb7g.cjs');
4
+ const addKnownErrorConstructor = require('./addKnownErrorConstructor-J1_ZUURa.cjs');
5
+ const NonError = require('./NonError-DqwGL5Cy.cjs');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ const defaultOptions = {
10
+ maxDepth: Number.POSITIVE_INFINITY
11
+ };
12
+ const deserializePlainObject = /* @__PURE__ */ __name((object, options, depth = 0) => {
13
+ if (addKnownErrorConstructor.isErrorLike(object)) {
14
+ return reconstructError(object, options, depth);
15
+ }
16
+ if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
17
+ return new NonError(JSON.stringify(object));
18
+ }
19
+ return new NonError(JSON.stringify(object));
20
+ }, "deserializePlainObject");
21
+ const reconstructAggregateError = /* @__PURE__ */ __name((Constructor, errors, message, options, depth) => {
22
+ const reconstructedErrors = errors.map((error_) => deserializeValue(error_, options, depth + 1));
23
+ return new Constructor(reconstructedErrors, message);
24
+ }, "reconstructAggregateError");
25
+ const reconstructError = /* @__PURE__ */ __name((serialized, options, depth) => {
26
+ if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
27
+ return new NonError(JSON.stringify(serialized));
28
+ }
29
+ const { cause, errors, message, name, stack, ...properties } = serialized;
30
+ const Constructor = addKnownErrorConstructor.getErrorConstructor(name) || Error;
31
+ const error = name === "AggregateError" && Array.isArray(errors) ? reconstructAggregateError(Constructor, errors, message, options, depth) : new Constructor(message);
32
+ if (!error.name && name) {
33
+ error.name = name;
34
+ }
35
+ if (message !== void 0) {
36
+ error.message = message;
37
+ }
38
+ if (stack) {
39
+ error.stack = stack;
40
+ }
41
+ restoreErrorProperties(error, properties, cause, name, options, depth);
42
+ if (cause !== void 0) {
43
+ error.cause = deserializeValue(cause, options, depth + 1);
44
+ }
45
+ makePropertiesEnumerable(error, serialized);
46
+ return error;
47
+ }, "reconstructError");
48
+ const deserializeValue = /* @__PURE__ */ __name((value, options, depth) => {
49
+ if (index.isPlainObject(value)) {
50
+ return deserializePlainObject(value, options, depth);
51
+ }
52
+ if (Array.isArray(value)) {
53
+ return value.map((item) => deserializeValue(item, options, depth));
54
+ }
55
+ return value;
56
+ }, "deserializeValue");
57
+ const restoreErrorProperties = /* @__PURE__ */ __name((error, properties, cause, name, options, depth) => {
58
+ const errorCopy = error;
59
+ for (const [key, value] of Object.entries(properties)) {
60
+ if (key === "cause" && cause !== void 0) {
61
+ continue;
62
+ } else if (key === "errors" && name === "AggregateError") {
63
+ continue;
64
+ } else {
65
+ errorCopy[key] = deserializeValue(value, options, depth + 1);
66
+ }
67
+ }
68
+ }, "restoreErrorProperties");
69
+ const makePropertiesEnumerable = /* @__PURE__ */ __name((error, serialized) => {
70
+ const errorProperties = /* @__PURE__ */ new Set();
71
+ errorProperties.add("name");
72
+ errorProperties.add("message");
73
+ errorProperties.add("stack");
74
+ for (const key of Object.keys(serialized)) {
75
+ errorProperties.add(key);
76
+ }
77
+ for (const key of errorProperties) {
78
+ if (key in error) {
79
+ const descriptor = Object.getOwnPropertyDescriptor(error, key);
80
+ if (descriptor && !descriptor.enumerable) {
81
+ Object.defineProperty(error, key, {
82
+ ...descriptor,
83
+ enumerable: true
84
+ });
85
+ }
86
+ }
87
+ }
88
+ }, "makePropertiesEnumerable");
89
+ const handlePrimitive = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handlePrimitive");
90
+ const handleArray = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handleArray");
91
+ const handlePlainObject = /* @__PURE__ */ __name((value, config) => {
92
+ if (addKnownErrorConstructor.isErrorLike(value)) {
93
+ return reconstructError(value, config, 0);
94
+ }
95
+ return deserializePlainObject(value, config);
96
+ }, "handlePlainObject");
97
+ const deserialize = /* @__PURE__ */ __name((value, options = {}) => {
98
+ const config = { ...defaultOptions, ...options };
99
+ if (value instanceof Error) {
100
+ return value;
101
+ }
102
+ if (value === null) {
103
+ return handlePrimitive(null);
104
+ }
105
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
106
+ return handlePrimitive(value);
107
+ }
108
+ if (Array.isArray(value)) {
109
+ return handleArray(value);
110
+ }
111
+ if (addKnownErrorConstructor.isErrorLike(value)) {
112
+ return reconstructError(value, config, 0);
113
+ }
114
+ if (index.isPlainObject(value)) {
115
+ return handlePlainObject(value, config);
116
+ }
117
+ return new NonError(JSON.stringify(value));
118
+ }, "deserialize");
119
+
120
+ module.exports = deserialize;
@@ -0,0 +1,118 @@
1
+ import { i as isPlainObject } from './index-BmoOJLvu.mjs';
2
+ import { isErrorLike, getErrorConstructor } from './addKnownErrorConstructor-DBmmT2OF.mjs';
3
+ import NonError from './NonError-BrwMc2LE.mjs';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const defaultOptions = {
8
+ maxDepth: Number.POSITIVE_INFINITY
9
+ };
10
+ const deserializePlainObject = /* @__PURE__ */ __name((object, options, depth = 0) => {
11
+ if (isErrorLike(object)) {
12
+ return reconstructError(object, options, depth);
13
+ }
14
+ if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
15
+ return new NonError(JSON.stringify(object));
16
+ }
17
+ return new NonError(JSON.stringify(object));
18
+ }, "deserializePlainObject");
19
+ const reconstructAggregateError = /* @__PURE__ */ __name((Constructor, errors, message, options, depth) => {
20
+ const reconstructedErrors = errors.map((error_) => deserializeValue(error_, options, depth + 1));
21
+ return new Constructor(reconstructedErrors, message);
22
+ }, "reconstructAggregateError");
23
+ const reconstructError = /* @__PURE__ */ __name((serialized, options, depth) => {
24
+ if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
25
+ return new NonError(JSON.stringify(serialized));
26
+ }
27
+ const { cause, errors, message, name, stack, ...properties } = serialized;
28
+ const Constructor = getErrorConstructor(name) || Error;
29
+ const error = name === "AggregateError" && Array.isArray(errors) ? reconstructAggregateError(Constructor, errors, message, options, depth) : new Constructor(message);
30
+ if (!error.name && name) {
31
+ error.name = name;
32
+ }
33
+ if (message !== void 0) {
34
+ error.message = message;
35
+ }
36
+ if (stack) {
37
+ error.stack = stack;
38
+ }
39
+ restoreErrorProperties(error, properties, cause, name, options, depth);
40
+ if (cause !== void 0) {
41
+ error.cause = deserializeValue(cause, options, depth + 1);
42
+ }
43
+ makePropertiesEnumerable(error, serialized);
44
+ return error;
45
+ }, "reconstructError");
46
+ const deserializeValue = /* @__PURE__ */ __name((value, options, depth) => {
47
+ if (isPlainObject(value)) {
48
+ return deserializePlainObject(value, options, depth);
49
+ }
50
+ if (Array.isArray(value)) {
51
+ return value.map((item) => deserializeValue(item, options, depth));
52
+ }
53
+ return value;
54
+ }, "deserializeValue");
55
+ const restoreErrorProperties = /* @__PURE__ */ __name((error, properties, cause, name, options, depth) => {
56
+ const errorCopy = error;
57
+ for (const [key, value] of Object.entries(properties)) {
58
+ if (key === "cause" && cause !== void 0) {
59
+ continue;
60
+ } else if (key === "errors" && name === "AggregateError") {
61
+ continue;
62
+ } else {
63
+ errorCopy[key] = deserializeValue(value, options, depth + 1);
64
+ }
65
+ }
66
+ }, "restoreErrorProperties");
67
+ const makePropertiesEnumerable = /* @__PURE__ */ __name((error, serialized) => {
68
+ const errorProperties = /* @__PURE__ */ new Set();
69
+ errorProperties.add("name");
70
+ errorProperties.add("message");
71
+ errorProperties.add("stack");
72
+ for (const key of Object.keys(serialized)) {
73
+ errorProperties.add(key);
74
+ }
75
+ for (const key of errorProperties) {
76
+ if (key in error) {
77
+ const descriptor = Object.getOwnPropertyDescriptor(error, key);
78
+ if (descriptor && !descriptor.enumerable) {
79
+ Object.defineProperty(error, key, {
80
+ ...descriptor,
81
+ enumerable: true
82
+ });
83
+ }
84
+ }
85
+ }
86
+ }, "makePropertiesEnumerable");
87
+ const handlePrimitive = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handlePrimitive");
88
+ const handleArray = /* @__PURE__ */ __name((value) => new NonError(JSON.stringify(value)), "handleArray");
89
+ const handlePlainObject = /* @__PURE__ */ __name((value, config) => {
90
+ if (isErrorLike(value)) {
91
+ return reconstructError(value, config, 0);
92
+ }
93
+ return deserializePlainObject(value, config);
94
+ }, "handlePlainObject");
95
+ const deserialize = /* @__PURE__ */ __name((value, options = {}) => {
96
+ const config = { ...defaultOptions, ...options };
97
+ if (value instanceof Error) {
98
+ return value;
99
+ }
100
+ if (value === null) {
101
+ return handlePrimitive(null);
102
+ }
103
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
104
+ return handlePrimitive(value);
105
+ }
106
+ if (Array.isArray(value)) {
107
+ return handleArray(value);
108
+ }
109
+ if (isErrorLike(value)) {
110
+ return reconstructError(value, config, 0);
111
+ }
112
+ if (isPlainObject(value)) {
113
+ return handlePlainObject(value, config);
114
+ }
115
+ return new NonError(JSON.stringify(value));
116
+ }, "deserialize");
117
+
118
+ export { deserialize as default };
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const errorHintFinder = {
4
+ handle: /* @__PURE__ */ __name(async (error) => {
5
+ if (error.hint === void 0) {
6
+ return void 0;
7
+ }
8
+ if (typeof error.hint === "string") {
9
+ return { body: error.hint };
10
+ }
11
+ if (typeof error.hint === "object" && typeof error.hint.body === "string") {
12
+ return error.hint;
13
+ }
14
+ if (Array.isArray(error.hint)) {
15
+ return { body: error.hint.join("\n") };
16
+ }
17
+ return void 0;
18
+ }, "handle"),
19
+ name: "errorHint",
20
+ priority: 1
21
+ };
22
+
23
+ export { errorHintFinder as default };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ const errorHintFinder = {
6
+ handle: /* @__PURE__ */ __name(async (error) => {
7
+ if (error.hint === void 0) {
8
+ return void 0;
9
+ }
10
+ if (typeof error.hint === "string") {
11
+ return { body: error.hint };
12
+ }
13
+ if (typeof error.hint === "object" && typeof error.hint.body === "string") {
14
+ return error.hint;
15
+ }
16
+ if (Array.isArray(error.hint)) {
17
+ return { body: error.hint.join("\n") };
18
+ }
19
+ return void 0;
20
+ }, "handle"),
21
+ name: "errorHint",
22
+ priority: 1
23
+ };
24
+
25
+ module.exports = errorHintFinder;
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const formatStackFrameLine = /* @__PURE__ */ __name((frame) => {
8
+ const method = frame.methodName && frame.methodName !== "<unknown>" ? `${frame.methodName} ` : "";
9
+ const file = frame.file ?? "<unknown>";
10
+ const line = frame.line ?? 0;
11
+ const column = frame.column ?? 0;
12
+ if (method.trim()) {
13
+ return ` at ${method}(${file}:${line}:${column})`;
14
+ }
15
+ return ` at ${file}:${line}:${column}`;
16
+ }, "formatStackFrameLine");
17
+ const formatStacktrace = /* @__PURE__ */ __name((frames, options) => {
18
+ const lines = [];
19
+ if (options?.header && (options.header.name || options.header.message)) {
20
+ const headerName = String(options.header.name || "Error");
21
+ const headerMessage = String(options.header.message || "");
22
+ lines.push(`${headerName}${headerMessage ? ": " : ""}${headerMessage}`);
23
+ }
24
+ for (const frame of frames) {
25
+ lines.push(formatStackFrameLine(frame));
26
+ }
27
+ return lines.join("\n");
28
+ }, "formatStacktrace");
29
+
30
+ exports.formatStackFrameLine = formatStackFrameLine;
31
+ exports.formatStacktrace = formatStacktrace;
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const formatStackFrameLine = /* @__PURE__ */ __name((frame) => {
4
+ const method = frame.methodName && frame.methodName !== "<unknown>" ? `${frame.methodName} ` : "";
5
+ const file = frame.file ?? "<unknown>";
6
+ const line = frame.line ?? 0;
7
+ const column = frame.column ?? 0;
8
+ if (method.trim()) {
9
+ return ` at ${method}(${file}:${line}:${column})`;
10
+ }
11
+ return ` at ${file}:${line}:${column}`;
12
+ }, "formatStackFrameLine");
13
+ const formatStacktrace = /* @__PURE__ */ __name((frames, options) => {
14
+ const lines = [];
15
+ if (options?.header && (options.header.name || options.header.message)) {
16
+ const headerName = String(options.header.name || "Error");
17
+ const headerMessage = String(options.header.message || "");
18
+ lines.push(`${headerName}${headerMessage ? ": " : ""}${headerMessage}`);
19
+ }
20
+ for (const frame of frames) {
21
+ lines.push(formatStackFrameLine(frame));
22
+ }
23
+ return lines.join("\n");
24
+ }, "formatStacktrace");
25
+
26
+ export { formatStackFrameLine, formatStacktrace };