@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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## @visulima/error [4.6.0](https://github.com/visulima/visulima/compare/@visulima/error@4.5.0...@visulima/error@4.6.0) (2025-09-12)
2
+
3
+ ### Features
4
+
5
+ * **error:** enhance error constructor handling and serialization tests ([036ba31](https://github.com/visulima/visulima/commit/036ba31acb182e9fa8c6e0b78ea10cf9f57c75f3))
6
+ * **error:** enhance error serialization and deserialization functionality ([3b07347](https://github.com/visulima/visulima/commit/3b073474807b40c65f692b037fccc6fe152cdc5b))
7
+
8
+ ### Bug Fixes
9
+
10
+ * **error:** enhance error serialization tests to preserve serialized values ([5ab8db3](https://github.com/visulima/visulima/commit/5ab8db3968142313b2f5c48b13605b843a1f0a1e))
11
+
12
+ ### Miscellaneous Chores
13
+
14
+ * update dependencies and fix linting issues ([0e802fe](https://github.com/visulima/visulima/commit/0e802fe02bb9ed791659cb5f3c77605ae5b42ec8))
15
+
16
+ ## @visulima/error [4.5.0](https://github.com/visulima/visulima/compare/@visulima/error@4.4.18...@visulima/error@4.5.0) (2025-09-07)
17
+
18
+ ### Features
19
+
20
+ * add error solution finder, added new format helper for trace ([82508bc](https://github.com/visulima/visulima/commit/82508bc42476da034b10c4023c823755a3c6b120))
21
+
22
+ ### Bug Fixes
23
+
24
+ * **error:** remove find cache dir dependency and add caching interface ([#514](https://github.com/visulima/visulima/issues/514)) ([caa1bfa](https://github.com/visulima/visulima/commit/caa1bfaf656009d76bcc2991e4a7ff706451670d))
25
+
26
+ ### Miscellaneous Chores
27
+
28
+ * update dependencies and remove obsolete documentation ([9e5e3c2](https://github.com/visulima/visulima/commit/9e5e3c2a68acf50d4b7abf8545d0edb85bb89078))
29
+ * update LICENSE.md with bundled dependencies and their licenses; add new fixture in pnpm-lock.yaml ([49d02a7](https://github.com/visulima/visulima/commit/49d02a7307168d9d2400e846d6f822a631d536e7))
30
+
1
31
  ## @visulima/error [4.4.18](https://github.com/visulima/visulima/compare/@visulima/error@4.4.17...@visulima/error@4.4.18) (2025-06-04)
2
32
 
3
33
 
package/LICENSE.md CHANGED
@@ -27,6 +27,131 @@ The published @visulima/error artifact additionally contains code with the follo
27
27
  MIT
28
28
 
29
29
  # Bundled dependencies:
30
+ ## @visulima/path
31
+ License: MIT
32
+ By: Daniel Bannert
33
+ Repository: git+https://github.com/visulima/visulima.git
34
+
35
+ > MIT License
36
+ >
37
+ > Copyright (c) 2024 visulima
38
+ >
39
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
40
+ > of this software and associated documentation files (the "Software"), to deal
41
+ > in the Software without restriction, including without limitation the rights
42
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
+ > copies of the Software, and to permit persons to whom the Software is
44
+ > furnished to do so, subject to the following conditions:
45
+ >
46
+ > The above copyright notice and this permission notice shall be included in all
47
+ > copies or substantial portions of the Software.
48
+ >
49
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
+ > SOFTWARE.
56
+ >
57
+ > ---
58
+ >
59
+ > MIT License
60
+ >
61
+ > Copyright (c) Pooya Parsa <pooya@pi0.io> - Daniel Roe <daniel@roe.dev>
62
+ >
63
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
64
+ > of this software and associated documentation files (the "Software"), to deal
65
+ > in the Software without restriction, including without limitation the rights
66
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
67
+ > copies of the Software, and to permit persons to whom the Software is
68
+ > furnished to do so, subject to the following conditions:
69
+ >
70
+ > The above copyright notice and this permission notice shall be included in all
71
+ > copies or substantial portions of the Software.
72
+ >
73
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
74
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
75
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
76
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
79
+ > SOFTWARE.
80
+ >
81
+ > ---
82
+ >
83
+ > Copyright Joyent, Inc. and other Node contributors.
84
+ >
85
+ > Permission is hereby granted, free of charge, to any person obtaining a
86
+ > copy of this software and associated documentation files (the
87
+ > "Software"), to deal in the Software without restriction, including
88
+ > without limitation the rights to use, copy, modify, merge, publish,
89
+ > distribute, sublicense, and/or sell copies of the Software, and to permit
90
+ > persons to whom the Software is furnished to do so, subject to the
91
+ > following conditions:
92
+ >
93
+ > The above copyright notice and this permission notice shall be included
94
+ > in all copies or substantial portions of the Software.
95
+ >
96
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
97
+ > OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
98
+ > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
99
+ > NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
100
+ > DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
101
+ > OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
102
+ > USE OR OTHER DEALINGS IN THE SOFTWARE.
103
+ >
104
+ > ---
105
+ >
106
+ > Bundled zeptomatch (https://github.com/fabiospampinato/zeptomatch)
107
+ >
108
+ > The MIT License (MIT)
109
+ >
110
+ > Copyright (c) 2023-present Fabio Spampinato
111
+ >
112
+ > Permission is hereby granted, free of charge, to any person obtaining a
113
+ > copy of this software and associated documentation files (the "Software"),
114
+ > to deal in the Software without restriction, including without limitation
115
+ > the rights to use, copy, modify, merge, publish, distribute, sublicense,
116
+ > and/or sell copies of the Software, and to permit persons to whom the
117
+ > Software is furnished to do so, subject to the following conditions:
118
+ >
119
+ > The above copyright notice and this permission notice shall be included in
120
+ > all copies or substantial portions of the Software.
121
+ >
122
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
123
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
124
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
125
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
126
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
127
+ > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
128
+ > DEALINGS IN THE SOFTWARE.
129
+ >
130
+ >
131
+ >
132
+ > # Licenses of bundled dependencies
133
+ > The published @visulima/path artifact additionally contains code with the following licenses:
134
+ > MIT
135
+ >
136
+ > # Bundled dependencies:
137
+ > ## binary-extensions
138
+ > License: MIT
139
+ > By: Sindre Sorhus
140
+ > Repository: sindresorhus/binary-extensions
141
+ >
142
+ > > MIT License
143
+ > >
144
+ > > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
145
+ > > Copyright (c) Paul Miller (https://paulmillr.com)
146
+ > >
147
+ > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
148
+ > >
149
+ > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
150
+ > >
151
+ > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
152
+
153
+ ---------------------------------------
154
+
30
155
  ## is-plain-obj
31
156
  License: MIT
32
157
  By: Sindre Sorhus
package/README.md CHANGED
@@ -39,6 +39,21 @@ yarn add @visulima/error
39
39
  pnpm add @visulima/error
40
40
  ```
41
41
 
42
+ ### Optional: AI integration
43
+
44
+ If you want to generate AI-powered solution hints, install these optional peer dependencies in your app:
45
+
46
+ ```sh
47
+ # pnpm
48
+ pnpm add ai
49
+
50
+ # npm
51
+ npm i ai
52
+
53
+ # yarn
54
+ yarn add ai
55
+ ```
56
+
42
57
  ## Usage
43
58
 
44
59
  ### Extend the VisulimaError
@@ -228,6 +243,109 @@ console.log(stack);
228
243
  // ];
229
244
  ```
230
245
 
246
+ ### Format stacktrace to a string
247
+
248
+ Turn parsed frames into a printable stack string (Node-style), optionally with a header line.
249
+
250
+ ```ts
251
+ import { parseStacktrace, stringifyStackFrames, formatStackFrameLine } from "@visulima/error";
252
+
253
+ const error = new Error("Boom");
254
+
255
+ const frames = parseStacktrace(error);
256
+
257
+ // Full stack as a single string with a header ("Error: Boom")
258
+ const stackText = stringifyStackFrames(frames, {
259
+ header: { name: error.name, message: error.message },
260
+ });
261
+ console.log(stackText);
262
+
263
+ // Format a single frame line (e.g., for custom rendering)
264
+ const firstLine = formatStackFrameLine(frames[0]);
265
+ ```
266
+
267
+ #### API
268
+
269
+ - `stringifyStackFrames(frames, options?)`
270
+ - `frames`: `Trace[]` — parsed frames from `parseStacktrace`
271
+ - `options.header`: `{ name?: string; message?: string }` — optional first-line header
272
+ - `formatStackFrameLine(frame)`
273
+ - `frame`: `Trace`
274
+ - returns a single formatted line like `" at myMethod (/path/file.ts:10:5)"`
275
+
276
+ ## Solutions (finders)
277
+
278
+ Generate helpful hints to fix an error. Two finders ship out of the box:
279
+
280
+ - Rule-based finder: provides best-effort fixes for common errors (ESM/CJS mix, missing default export, DNS issues, hydration mismatch, etc.)
281
+ - Error-hint finder: reads `error.hint` you attach to an `Error` or `VisulimaError`
282
+
283
+ Both return a `Solution` (`{ header?: string; body: string }`) or `undefined`.
284
+
285
+ ```ts
286
+ import { codeFrame } from "@visulima/error";
287
+ import { ruleBasedFinder, errorHintFinder } from "@visulima/error";
288
+
289
+ const error = new Error("Cannot read properties of undefined (reading 'x')");
290
+
291
+ const source = "const o = undefined\nconsole.log(o.x)\n";
292
+ const snippet = codeFrame(source, { start: { line: 2, column: 13 } });
293
+
294
+ const fileCtx = {
295
+ file: "/path/to/file.ts",
296
+ line: 2,
297
+ language: "ts",
298
+ snippet,
299
+ };
300
+
301
+ // 1) Rule-based finder
302
+ const ruleHint = await ruleBasedFinder.handle(error, fileCtx);
303
+ if (ruleHint) {
304
+ console.log(ruleHint.header);
305
+ console.log(ruleHint.body);
306
+ }
307
+
308
+ // 2) Error-hint finder (reads error.hint)
309
+ const custom = new Error("failed") as Error & { hint?: unknown };
310
+ custom.hint = ["Check the environment variables.", "Ensure the service is reachable."];
311
+ const hintHint = await errorHintFinder.handle(custom, { file: "", line: 0 });
312
+ ```
313
+
314
+ ### AI solution helper (optional)
315
+
316
+ You can build an AI prompt with rich context and render the LLM result into a nice HTML snippet.
317
+
318
+ ```ts
319
+ import { aiPrompt, aiSolutionResponse } from "@visulima/error/solution/ai";
320
+ // or
321
+ // import aiPrompt from "@visulima/error/solution/ai/prompt";
322
+
323
+ const prompt = aiPrompt({
324
+ applicationType: undefined,
325
+ error,
326
+ file: fileCtx,
327
+ });
328
+
329
+ // Send `prompt` to your LLM of choice.
330
+ // When you receive the model's text output, format it for display:
331
+ const html = aiSolutionResponse(modelText);
332
+ ```
333
+
334
+ You may also use a convenience finder that calls an AI provider for you (requires optional peer dep `ai`):
335
+
336
+ ```ts
337
+ import { aiFinder } from "@visulima/error/solution/ai";
338
+ import { createOpenAI } from "@ai-sdk/openai";
339
+
340
+ const client = createOpenAI(apiKey ? { apiKey } : undefined);
341
+
342
+ const findAI = aiFinder(client(modelId), {
343
+ temperature: 0,
344
+ });
345
+
346
+ const aiHint = await findAI.handle(error, fileCtx);
347
+ ```
348
+
231
349
  ### API
232
350
 
233
351
  #### error
@@ -278,6 +396,67 @@ const errorString = JSON.stringify(errorObject);
278
396
  const newErrorObject = JSON.parse(errorString);
279
397
  ```
280
398
 
399
+ ## `deserialize` an error object
400
+
401
+ Deserialize a previously serialized error back to an Error instance.
402
+
403
+ - Automatically detects error-like objects
404
+ - Reconstructs proper Error instances with correct constructors
405
+ - Handles custom error classes registered with `addKnownErrorConstructor`
406
+ - Supports AggregateError deserialization
407
+ - Preserves error properties and cause chains
408
+ - Wraps non-error-like objects in NonError
409
+
410
+ ```ts
411
+ import { serializeError, deserializeError } from "@visulima/error";
412
+
413
+ const error = new TypeError("example");
414
+ const serialized = serializeError(error);
415
+
416
+ // Deserialize back to Error instance
417
+ const deserialized = deserializeError(serialized);
418
+
419
+ console.log(deserialized instanceof TypeError); // true
420
+ console.log(deserialized.message); // "example"
421
+ ```
422
+
423
+ ### Registering Custom Error Constructors
424
+
425
+ ```ts
426
+ import { addKnownErrorConstructor, deserializeError } from "@visulima/error";
427
+
428
+ class CustomError extends Error {
429
+ constructor(message: string, code: number) {
430
+ super(message);
431
+ this.name = "CustomError";
432
+ this.code = code;
433
+ }
434
+ }
435
+
436
+ // Register the custom error constructor
437
+ addKnownErrorConstructor(CustomError);
438
+
439
+ // Now it can be deserialized properly
440
+ const serialized = { name: "CustomError", message: "test", code: 42 };
441
+ const deserialized = deserializeError(serialized);
442
+
443
+ console.log(deserialized instanceof CustomError); // true
444
+ console.log(deserialized.code); // 42
445
+ ```
446
+
447
+ ### NonError for Non-Error Objects
448
+
449
+ When deserializing objects that don't look like errors, they're wrapped in a `NonError`:
450
+
451
+ ```ts
452
+ import { deserializeError, NonError } from "@visulima/error";
453
+
454
+ const deserialized = deserializeError({ foo: "bar" });
455
+
456
+ console.log(deserialized instanceof NonError); // true
457
+ console.log(deserialized.message); // '{"foo":"bar"}'
458
+ ```
459
+
281
460
  ## renderError - pretty print an error
282
461
 
283
462
  ```ts
@@ -374,6 +553,89 @@ Default: `false`
374
553
 
375
554
  Hide the error message.
376
555
 
556
+ ### `deserializeError`
557
+
558
+ Deserialize a value back to its original form. If the value looks like a serialized error, it will be reconstructed as an Error instance. Otherwise, it will be wrapped in a NonError.
559
+
560
+ ```ts
561
+ import { deserializeError } from "@visulima/error";
562
+
563
+ const deserialized = deserializeError({ name: "TypeError", message: "example" });
564
+
565
+ console.log(deserialized instanceof TypeError); // true
566
+ ```
567
+
568
+ #### value
569
+
570
+ Type: `unknown`
571
+
572
+ The value to deserialize.
573
+
574
+ #### options
575
+
576
+ Type: `object`
577
+
578
+ ##### options.maxDepth
579
+
580
+ Type: `number` \
581
+ Default: `Number.POSITIVE_INFINITY`
582
+
583
+ The maximum depth to deserialize nested objects.
584
+
585
+ ### `NonError`
586
+
587
+ A class for wrapping non-error-like objects during deserialization.
588
+
589
+ ```ts
590
+ import { NonError } from "@visulima/error";
591
+
592
+ const nonError = new NonError("some message");
593
+
594
+ console.log(nonError instanceof Error); // true
595
+ console.log(nonError.name); // "NonError"
596
+ ```
597
+
598
+ ### `addKnownErrorConstructor`
599
+
600
+ Add a known error constructor to the registry for proper deserialization.
601
+
602
+ ```ts
603
+ import { addKnownErrorConstructor } from "@visulima/error";
604
+
605
+ class CustomError extends Error {
606
+ constructor(message: string) {
607
+ super(message);
608
+ this.name = "CustomError";
609
+ }
610
+ }
611
+
612
+ addKnownErrorConstructor(CustomError);
613
+ ```
614
+
615
+ #### constructor
616
+
617
+ Type: `new (...args: unknown[]) => Error`
618
+
619
+ The error constructor to add to the registry.
620
+
621
+ ### `isErrorLike`
622
+
623
+ Check if an object looks like a serialized error.
624
+
625
+ ```ts
626
+ import { isErrorLike } from "@visulima/error";
627
+
628
+ const obj = { name: "TypeError", message: "example" };
629
+
630
+ console.log(isErrorLike(obj)); // true
631
+ ```
632
+
633
+ #### value
634
+
635
+ Type: `unknown`
636
+
637
+ The value to check.
638
+
377
639
  ### captureRawStackTrace
378
640
 
379
641
  Capture a raw stack trace.
@@ -102,9 +102,9 @@ const codeFrame = /* @__PURE__ */ __name((source, loc, options) => {
102
102
  let frame = lines.slice(start, end).map((line, index) => {
103
103
  const number = start + 1 + index;
104
104
  const hasMarker = markerLines[number];
105
- const paddedNumber = (" " + number).slice(-numberMaxWidth);
105
+ const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
106
106
  const lastMarkerLine = !markerLines[number + 1];
107
- const gutter = " " + paddedNumber + (config.showGutter ? " |" : "");
107
+ const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
108
108
  if (hasMarker) {
109
109
  let markerLine = "";
110
110
  if (Array.isArray(hasMarker)) {
@@ -121,12 +121,13 @@ const codeFrame = /* @__PURE__ */ __name((source, loc, options) => {
121
121
  markerLine += ` ${colorizeMessage(config.message)}`;
122
122
  }
123
123
  }
124
- return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? " " + line : "", markerLine].join("");
124
+ return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
125
125
  }
126
- return config.prefix + " " + colorizeGutter(gutter) + (line.length > 0 ? " " + line : "");
126
+ return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
127
127
  }).join("\n");
128
128
  if (config.message && !hasColumns) {
129
- frame = config.prefix + " ".repeat(numberMaxWidth + 1) + config.message + "\n" + frame;
129
+ frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
130
+ ${frame}`;
130
131
  }
131
132
  return frame;
132
133
  }, "codeFrame");
@@ -98,9 +98,9 @@ const codeFrame = /* @__PURE__ */ __name((source, loc, options) => {
98
98
  let frame = lines.slice(start, end).map((line, index) => {
99
99
  const number = start + 1 + index;
100
100
  const hasMarker = markerLines[number];
101
- const paddedNumber = (" " + number).slice(-numberMaxWidth);
101
+ const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
102
102
  const lastMarkerLine = !markerLines[number + 1];
103
- const gutter = " " + paddedNumber + (config.showGutter ? " |" : "");
103
+ const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
104
104
  if (hasMarker) {
105
105
  let markerLine = "";
106
106
  if (Array.isArray(hasMarker)) {
@@ -117,12 +117,13 @@ const codeFrame = /* @__PURE__ */ __name((source, loc, options) => {
117
117
  markerLine += ` ${colorizeMessage(config.message)}`;
118
118
  }
119
119
  }
120
- return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? " " + line : "", markerLine].join("");
120
+ return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
121
121
  }
122
- return config.prefix + " " + colorizeGutter(gutter) + (line.length > 0 ? " " + line : "");
122
+ return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
123
123
  }).join("\n");
124
124
  if (config.message && !hasColumns) {
125
- frame = config.prefix + " ".repeat(numberMaxWidth + 1) + config.message + "\n" + frame;
125
+ frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
126
+ ${frame}`;
126
127
  }
127
128
  return frame;
128
129
  }, "codeFrame");
@@ -4,15 +4,22 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
4
4
 
5
5
  const captureRawStackTrace = require('../packem_shared/captureRawStackTrace-ClSI1tHb.cjs');
6
6
  const getErrorCauses = require('../packem_shared/getErrorCauses-miTeYJEG.cjs');
7
- const renderError = require('../packem_shared/renderError-CXZTAXig.cjs');
8
- const serializeError = require('../packem_shared/serializeError-CT7s0Ffk.cjs');
9
- const isVisulimaError = require('../packem_shared/isVisulimaError-BVLWvREw.cjs');
7
+ const renderError = require('../packem_shared/renderError-n3kXGdYj.cjs');
8
+ const deserializeError = require('../packem_shared/deserializeError-Be3qOGBQ.cjs');
9
+ const addKnownErrorConstructor = require('../packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs');
10
+ const NonError = require('../packem_shared/NonError-DqwGL5Cy.cjs');
11
+ const serializeError = require('../packem_shared/serializeError-Dt7oFM2R.cjs');
12
+ const isVisulimaError = require('../packem_shared/isVisulimaError-Bb1_TB6w.cjs');
10
13
 
11
14
 
12
15
 
13
16
  exports.captureRawStackTrace = captureRawStackTrace;
14
17
  exports.getErrorCauses = getErrorCauses;
15
18
  exports.renderError = renderError.renderError;
19
+ exports.deserializeError = deserializeError;
20
+ exports.addKnownErrorConstructor = addKnownErrorConstructor.addKnownErrorConstructor;
21
+ exports.isErrorLike = addKnownErrorConstructor.isErrorLike;
22
+ exports.NonError = NonError;
16
23
  exports.serializeError = serializeError.serialize;
17
24
  exports.VisulimaError = isVisulimaError.VisulimaError;
18
25
  exports.isVisulimaError = isVisulimaError.isVisulimaError;
@@ -54,6 +54,20 @@ type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
54
54
  };
55
55
  declare const renderError: (error: AggregateError | Error | VisulimaError, options?: Partial<Options$1>) => string;
56
56
 
57
+ interface DeserializeOptions {
58
+ maxDepth?: number;
59
+ }
60
+ type DeserializeOptionsType = DeserializeOptions;
61
+ declare const deserialize: (value: unknown, options?: DeserializeOptionsType) => Error;
62
+
63
+ type ErrorConstructor = new (...arguments_: any[]) => Error;
64
+ declare const addKnownErrorConstructor: (constructor: ErrorConstructor, name?: string) => void;
65
+ declare const isErrorLike: (value: unknown) => value is {
66
+ message?: string;
67
+ name?: string;
68
+ stack?: string;
69
+ };
70
+
57
71
  type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
58
72
  aggregateErrors?: SerializedError<ErrorType>[];
59
73
  cause?: unknown;
@@ -64,6 +78,10 @@ type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
64
78
  stack?: string;
65
79
  };
66
80
 
81
+ declare class NonError extends Error {
82
+ constructor(message: string);
83
+ }
84
+
67
85
  interface JsonError extends Error {
68
86
  toJSON: () => SerializedError;
69
87
  }
@@ -74,4 +92,4 @@ type Options = {
74
92
  };
75
93
  declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
76
94
 
77
- export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, type Options$1 as RenderErrorOptions, type SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serialize as serializeError };
95
+ export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, NonError, type Options$1 as RenderErrorOptions, type SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserialize as deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serialize as serializeError };
@@ -54,6 +54,20 @@ type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
54
54
  };
55
55
  declare const renderError: (error: AggregateError | Error | VisulimaError, options?: Partial<Options$1>) => string;
56
56
 
57
+ interface DeserializeOptions {
58
+ maxDepth?: number;
59
+ }
60
+ type DeserializeOptionsType = DeserializeOptions;
61
+ declare const deserialize: (value: unknown, options?: DeserializeOptionsType) => Error;
62
+
63
+ type ErrorConstructor = new (...arguments_: any[]) => Error;
64
+ declare const addKnownErrorConstructor: (constructor: ErrorConstructor, name?: string) => void;
65
+ declare const isErrorLike: (value: unknown) => value is {
66
+ message?: string;
67
+ name?: string;
68
+ stack?: string;
69
+ };
70
+
57
71
  type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
58
72
  aggregateErrors?: SerializedError<ErrorType>[];
59
73
  cause?: unknown;
@@ -64,6 +78,10 @@ type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
64
78
  stack?: string;
65
79
  };
66
80
 
81
+ declare class NonError extends Error {
82
+ constructor(message: string);
83
+ }
84
+
67
85
  interface JsonError extends Error {
68
86
  toJSON: () => SerializedError;
69
87
  }
@@ -74,4 +92,4 @@ type Options = {
74
92
  };
75
93
  declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
76
94
 
77
- export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, type Options$1 as RenderErrorOptions, type SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serialize as serializeError };
95
+ export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, NonError, type Options$1 as RenderErrorOptions, type SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserialize as deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serialize as serializeError };
@@ -54,6 +54,20 @@ type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
54
54
  };
55
55
  declare const renderError: (error: AggregateError | Error | VisulimaError, options?: Partial<Options$1>) => string;
56
56
 
57
+ interface DeserializeOptions {
58
+ maxDepth?: number;
59
+ }
60
+ type DeserializeOptionsType = DeserializeOptions;
61
+ declare const deserialize: (value: unknown, options?: DeserializeOptionsType) => Error;
62
+
63
+ type ErrorConstructor = new (...arguments_: any[]) => Error;
64
+ declare const addKnownErrorConstructor: (constructor: ErrorConstructor, name?: string) => void;
65
+ declare const isErrorLike: (value: unknown) => value is {
66
+ message?: string;
67
+ name?: string;
68
+ stack?: string;
69
+ };
70
+
57
71
  type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
58
72
  aggregateErrors?: SerializedError<ErrorType>[];
59
73
  cause?: unknown;
@@ -64,6 +78,10 @@ type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
64
78
  stack?: string;
65
79
  };
66
80
 
81
+ declare class NonError extends Error {
82
+ constructor(message: string);
83
+ }
84
+
67
85
  interface JsonError extends Error {
68
86
  toJSON: () => SerializedError;
69
87
  }
@@ -74,4 +92,4 @@ type Options = {
74
92
  };
75
93
  declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
76
94
 
77
- export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, type Options$1 as RenderErrorOptions, type SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serialize as serializeError };
95
+ export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, NonError, type Options$1 as RenderErrorOptions, type SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserialize as deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serialize as serializeError };
@@ -1,5 +1,8 @@
1
1
  export { default as captureRawStackTrace } from '../packem_shared/captureRawStackTrace-Tl3Rqkat.mjs';
2
2
  export { default as getErrorCauses } from '../packem_shared/getErrorCauses-CG_JRE6j.mjs';
3
- export { renderError } from '../packem_shared/renderError-BWpM2m6k.mjs';
4
- export { serialize as serializeError } from '../packem_shared/serializeError-DusTUACt.mjs';
5
- export { VisulimaError, isVisulimaError } from '../packem_shared/isVisulimaError-H6TqEA42.mjs';
3
+ export { renderError } from '../packem_shared/renderError-Cn8M0fQ3.mjs';
4
+ export { default as deserializeError } from '../packem_shared/deserializeError-DuzHucBb.mjs';
5
+ export { addKnownErrorConstructor, isErrorLike } from '../packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs';
6
+ export { default as NonError } from '../packem_shared/NonError-BrwMc2LE.mjs';
7
+ export { serialize as serializeError } from '../packem_shared/serializeError-DHIelq5o.mjs';
8
+ export { VisulimaError, isVisulimaError } from '../packem_shared/isVisulimaError-zyd80Gui.mjs';