@visulima/error 4.5.0 → 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.
- package/CHANGELOG.md +15 -0
- package/README.md +148 -4
- package/dist/code-frame/index.cjs +6 -5
- package/dist/code-frame/index.mjs +6 -5
- package/dist/error/index.cjs +10 -3
- package/dist/error/index.d.cts +19 -1
- package/dist/error/index.d.mts +19 -1
- package/dist/error/index.d.ts +19 -1
- package/dist/error/index.mjs +6 -3
- package/dist/index.cjs +14 -7
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +10 -7
- package/dist/packem_shared/NonError-BrwMc2LE.mjs +13 -0
- package/dist/packem_shared/NonError-DqwGL5Cy.cjs +15 -0
- package/dist/packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs +32 -0
- package/dist/packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs +39 -0
- package/dist/packem_shared/{aiFinder-BGfwKKxE.cjs → aiFinder-BR9Pq804.cjs} +19 -23
- package/dist/packem_shared/{aiFinder-Bk1vt0_x.mjs → aiFinder-CFHvOjD8.mjs} +19 -23
- package/dist/packem_shared/{aiSolutionResponse-bDi4ad8f.mjs → aiSolutionResponse-BaN1M990.mjs} +3 -2
- package/dist/packem_shared/{aiSolutionResponse-BPckbL56.cjs → aiSolutionResponse-Cqi0mFxy.cjs} +3 -2
- package/dist/packem_shared/deserializeError-Be3qOGBQ.cjs +120 -0
- package/dist/packem_shared/deserializeError-DuzHucBb.mjs +118 -0
- package/dist/packem_shared/index-BmoOJLvu.mjs +12 -0
- package/dist/packem_shared/index-C53Tqb7g.cjs +14 -0
- package/dist/packem_shared/{indexToLineColumn-Dx91YDU1.mjs → indexToLineColumn-CKQKtKEK.mjs} +0 -2
- package/dist/packem_shared/{indexToLineColumn-DjmjeiIY.cjs → indexToLineColumn-Cro5eT8v.cjs} +0 -2
- package/dist/packem_shared/{isVisulimaError-BVLWvREw.cjs → isVisulimaError-Bb1_TB6w.cjs} +0 -1
- package/dist/packem_shared/{isVisulimaError-H6TqEA42.mjs → isVisulimaError-zyd80Gui.mjs} +0 -1
- package/dist/packem_shared/{parseStacktrace-BKGoWCwC.mjs → parseStacktrace-BlguTUcF.mjs} +10 -15
- package/dist/packem_shared/{parseStacktrace-6pFoXW43.cjs → parseStacktrace-woJgU2XY.cjs} +10 -15
- package/dist/packem_shared/{renderError-BWpM2m6k.mjs → renderError-Cn8M0fQ3.mjs} +37 -22
- package/dist/packem_shared/{renderError-CXZTAXig.cjs → renderError-n3kXGdYj.cjs} +35 -20
- package/dist/packem_shared/{ruleBasedFinder-BYrndubA.mjs → ruleBasedFinder-Cbmc6N7f.mjs} +1 -1
- package/dist/packem_shared/{ruleBasedFinder-y_-5kbeT.cjs → ruleBasedFinder-CkybTSHw.cjs} +1 -1
- package/dist/packem_shared/{serializeError-DusTUACt.mjs → serializeError-DHIelq5o.mjs} +2 -11
- package/dist/packem_shared/{serializeError-CT7s0Ffk.cjs → serializeError-Dt7oFM2R.cjs} +3 -12
- package/dist/solution/ai/index.cjs +2 -2
- package/dist/solution/ai/index.d.cts +2 -2
- package/dist/solution/ai/index.d.mts +2 -2
- package/dist/solution/ai/index.d.ts +2 -2
- package/dist/solution/ai/index.mjs +2 -2
- package/dist/solution/index.cjs +1 -1
- package/dist/solution/index.mjs +1 -1
- package/dist/stacktrace/index.cjs +1 -1
- package/dist/stacktrace/index.d.cts +2 -2
- package/dist/stacktrace/index.d.mts +2 -2
- package/dist/stacktrace/index.d.ts +2 -2
- package/dist/stacktrace/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
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
|
+
|
|
1
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)
|
|
2
17
|
|
|
3
18
|
### Features
|
package/README.md
CHANGED
|
@@ -267,11 +267,11 @@ const firstLine = formatStackFrameLine(frames[0]);
|
|
|
267
267
|
#### API
|
|
268
268
|
|
|
269
269
|
- `stringifyStackFrames(frames, options?)`
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
- `frames`: `Trace[]` — parsed frames from `parseStacktrace`
|
|
271
|
+
- `options.header`: `{ name?: string; message?: string }` — optional first-line header
|
|
272
272
|
- `formatStackFrameLine(frame)`
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
- `frame`: `Trace`
|
|
274
|
+
- returns a single formatted line like `" at myMethod (/path/file.ts:10:5)"`
|
|
275
275
|
|
|
276
276
|
## Solutions (finders)
|
|
277
277
|
|
|
@@ -396,6 +396,67 @@ const errorString = JSON.stringify(errorObject);
|
|
|
396
396
|
const newErrorObject = JSON.parse(errorString);
|
|
397
397
|
```
|
|
398
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
|
+
|
|
399
460
|
## renderError - pretty print an error
|
|
400
461
|
|
|
401
462
|
```ts
|
|
@@ -492,6 +553,89 @@ Default: `false`
|
|
|
492
553
|
|
|
493
554
|
Hide the error message.
|
|
494
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
|
+
|
|
495
639
|
### captureRawStackTrace
|
|
496
640
|
|
|
497
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 =
|
|
105
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
106
106
|
const lastMarkerLine = !markerLines[number + 1];
|
|
107
|
-
const gutter =
|
|
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 ?
|
|
124
|
+
return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
|
125
125
|
}
|
|
126
|
-
return config.prefix
|
|
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
|
|
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 =
|
|
101
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
102
102
|
const lastMarkerLine = !markerLines[number + 1];
|
|
103
|
-
const gutter =
|
|
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 ?
|
|
120
|
+
return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
|
121
121
|
}
|
|
122
|
-
return config.prefix
|
|
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
|
|
125
|
+
frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
|
|
126
|
+
${frame}`;
|
|
126
127
|
}
|
|
127
128
|
return frame;
|
|
128
129
|
}, "codeFrame");
|
package/dist/error/index.cjs
CHANGED
|
@@ -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-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
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;
|
package/dist/error/index.d.cts
CHANGED
|
@@ -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 };
|
package/dist/error/index.d.mts
CHANGED
|
@@ -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 };
|
package/dist/error/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/error/index.mjs
CHANGED
|
@@ -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-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
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';
|
package/dist/index.cjs
CHANGED
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
4
|
|
|
5
5
|
const codeFrame_index = require('./code-frame/index.cjs');
|
|
6
|
-
const indexToLineColumn = require('./packem_shared/indexToLineColumn-
|
|
6
|
+
const indexToLineColumn = require('./packem_shared/indexToLineColumn-Cro5eT8v.cjs');
|
|
7
7
|
const solution_ai_aiPrompt = require('./solution/ai/ai-prompt.cjs');
|
|
8
|
-
const aiSolutionResponse = require('./packem_shared/aiSolutionResponse-
|
|
8
|
+
const aiSolutionResponse = require('./packem_shared/aiSolutionResponse-Cqi0mFxy.cjs');
|
|
9
9
|
const errorHintFinder = require('./packem_shared/errorHintFinder-DZugFHq0.cjs');
|
|
10
|
-
const ruleBasedFinder = require('./packem_shared/ruleBasedFinder-
|
|
10
|
+
const ruleBasedFinder = require('./packem_shared/ruleBasedFinder-CkybTSHw.cjs');
|
|
11
11
|
const captureRawStackTrace = require('./packem_shared/captureRawStackTrace-ClSI1tHb.cjs');
|
|
12
|
+
const deserializeError = require('./packem_shared/deserializeError-Be3qOGBQ.cjs');
|
|
12
13
|
const getErrorCauses = require('./packem_shared/getErrorCauses-miTeYJEG.cjs');
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
14
|
+
const NonError = require('./packem_shared/NonError-DqwGL5Cy.cjs');
|
|
15
|
+
const parseStacktrace = require('./packem_shared/parseStacktrace-woJgU2XY.cjs');
|
|
16
|
+
const addKnownErrorConstructor = require('./packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs');
|
|
17
|
+
const isVisulimaError = require('./packem_shared/isVisulimaError-Bb1_TB6w.cjs');
|
|
18
|
+
const renderError = require('./packem_shared/renderError-n3kXGdYj.cjs');
|
|
19
|
+
const serializeError = require('./packem_shared/serializeError-Dt7oFM2R.cjs');
|
|
17
20
|
const formatStackFrameLine = require('./packem_shared/formatStackFrameLine-DcXSX--m.cjs');
|
|
18
21
|
|
|
19
22
|
|
|
@@ -26,8 +29,12 @@ exports.aiSolutionResponse = aiSolutionResponse;
|
|
|
26
29
|
exports.errorHintFinder = errorHintFinder;
|
|
27
30
|
exports.ruleBasedFinder = ruleBasedFinder;
|
|
28
31
|
exports.captureRawStackTrace = captureRawStackTrace;
|
|
32
|
+
exports.deserializeError = deserializeError;
|
|
29
33
|
exports.getErrorCauses = getErrorCauses;
|
|
34
|
+
exports.NonError = NonError;
|
|
30
35
|
exports.parseStacktrace = parseStacktrace;
|
|
36
|
+
exports.addKnownErrorConstructor = addKnownErrorConstructor.addKnownErrorConstructor;
|
|
37
|
+
exports.isErrorLike = addKnownErrorConstructor.isErrorLike;
|
|
31
38
|
exports.VisulimaError = isVisulimaError.VisulimaError;
|
|
32
39
|
exports.isVisulimaError = isVisulimaError.isVisulimaError;
|
|
33
40
|
exports.renderError = renderError.renderError;
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ export { default as aiPrompt } from './solution/ai/ai-prompt.cjs';
|
|
|
3
3
|
export { a as aiSolutionResponse } from './packem_shared/ai-solution-response-BuaDQAEU.cjs';
|
|
4
4
|
export { errorHintFinder, ruleBasedFinder } from './solution/index.cjs';
|
|
5
5
|
export { S as Solution, a as SolutionError, b as SolutionFinder, c as SolutionFinderFile } from './packem_shared/types-BtQS7FHG.cjs';
|
|
6
|
-
export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, RenderErrorOptions, SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serializeError } from './error/index.cjs';
|
|
6
|
+
export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, NonError, RenderErrorOptions, SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serializeError } from './error/index.cjs';
|
|
7
7
|
export { Trace, TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace } from './stacktrace/index.cjs';
|
|
8
8
|
export { C as CodeFrameLocation, a as CodeFrameNodeLocation, b as CodeFrameOptions, c as ColorizeMethod } from './packem_shared/types-CrVmNoPV.cjs';
|
|
9
9
|
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ export { default as aiPrompt } from './solution/ai/ai-prompt.mjs';
|
|
|
3
3
|
export { a as aiSolutionResponse } from './packem_shared/ai-solution-response-BuaDQAEU.mjs';
|
|
4
4
|
export { errorHintFinder, ruleBasedFinder } from './solution/index.mjs';
|
|
5
5
|
export { S as Solution, a as SolutionError, b as SolutionFinder, c as SolutionFinderFile } from './packem_shared/types-BtQS7FHG.mjs';
|
|
6
|
-
export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, RenderErrorOptions, SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serializeError } from './error/index.mjs';
|
|
6
|
+
export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, NonError, RenderErrorOptions, SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serializeError } from './error/index.mjs';
|
|
7
7
|
export { Trace, TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace } from './stacktrace/index.mjs';
|
|
8
8
|
export { C as CodeFrameLocation, a as CodeFrameNodeLocation, b as CodeFrameOptions, c as ColorizeMethod } from './packem_shared/types-CrVmNoPV.mjs';
|
|
9
9
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { default as aiPrompt } from './solution/ai/ai-prompt.js';
|
|
|
3
3
|
export { a as aiSolutionResponse } from './packem_shared/ai-solution-response-BuaDQAEU.js';
|
|
4
4
|
export { errorHintFinder, ruleBasedFinder } from './solution/index.js';
|
|
5
5
|
export { S as Solution, a as SolutionError, b as SolutionFinder, c as SolutionFinderFile } from './packem_shared/types-BtQS7FHG.js';
|
|
6
|
-
export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, RenderErrorOptions, SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serializeError } from './error/index.js';
|
|
6
|
+
export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, NonError, RenderErrorOptions, SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serializeError } from './error/index.js';
|
|
7
7
|
export { Trace, TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace } from './stacktrace/index.js';
|
|
8
8
|
export { C as CodeFrameLocation, a as CodeFrameNodeLocation, b as CodeFrameOptions, c as ColorizeMethod } from './packem_shared/types-CrVmNoPV.js';
|
|
9
9
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.mjs';
|
|
2
|
-
export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-
|
|
2
|
+
export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-CKQKtKEK.mjs';
|
|
3
3
|
export { default as aiPrompt } from './solution/ai/ai-prompt.mjs';
|
|
4
|
-
export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-
|
|
4
|
+
export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-BaN1M990.mjs';
|
|
5
5
|
export { default as errorHintFinder } from './packem_shared/errorHintFinder-CQy_qIK3.mjs';
|
|
6
|
-
export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-
|
|
6
|
+
export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-Cbmc6N7f.mjs';
|
|
7
7
|
export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-Tl3Rqkat.mjs';
|
|
8
|
+
export { default as deserializeError } from './packem_shared/deserializeError-DuzHucBb.mjs';
|
|
8
9
|
export { default as getErrorCauses } from './packem_shared/getErrorCauses-CG_JRE6j.mjs';
|
|
9
|
-
export { default as
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
10
|
+
export { default as NonError } from './packem_shared/NonError-BrwMc2LE.mjs';
|
|
11
|
+
export { default as parseStacktrace } from './packem_shared/parseStacktrace-BlguTUcF.mjs';
|
|
12
|
+
export { addKnownErrorConstructor, isErrorLike } from './packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs';
|
|
13
|
+
export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-zyd80Gui.mjs';
|
|
14
|
+
export { renderError } from './packem_shared/renderError-Cn8M0fQ3.mjs';
|
|
15
|
+
export { serialize as serializeError } from './packem_shared/serializeError-DHIelq5o.mjs';
|
|
13
16
|
export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-DqkmKWH3.mjs';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class NonError extends Error {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "NonError");
|
|
6
|
+
}
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "NonError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { NonError as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
class NonError extends Error {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "NonError");
|
|
8
|
+
}
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "NonError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = NonError;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const defaultErrorConstructors = /* @__PURE__ */ new Map([
|
|
4
|
+
["Error", Error],
|
|
5
|
+
["EvalError", EvalError],
|
|
6
|
+
["RangeError", RangeError],
|
|
7
|
+
["ReferenceError", ReferenceError],
|
|
8
|
+
["SyntaxError", SyntaxError],
|
|
9
|
+
["TypeError", TypeError],
|
|
10
|
+
["URIError", URIError]
|
|
11
|
+
]);
|
|
12
|
+
if (typeof AggregateError !== "undefined") {
|
|
13
|
+
defaultErrorConstructors.set("AggregateError", AggregateError);
|
|
14
|
+
}
|
|
15
|
+
const addKnownErrorConstructor = /* @__PURE__ */ __name((constructor, name) => {
|
|
16
|
+
let instance;
|
|
17
|
+
try {
|
|
18
|
+
instance = new constructor();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new Error(`The error constructor "${constructor.name}" is not compatible`, { cause: error });
|
|
21
|
+
}
|
|
22
|
+
const resolvedName = name ?? instance.name;
|
|
23
|
+
if (defaultErrorConstructors.has(resolvedName)) {
|
|
24
|
+
throw new Error(`The error constructor "${resolvedName}" is already known.`);
|
|
25
|
+
}
|
|
26
|
+
defaultErrorConstructors.set(resolvedName, constructor);
|
|
27
|
+
}, "addKnownErrorConstructor");
|
|
28
|
+
const getKnownErrorConstructors = /* @__PURE__ */ __name(() => new Map(defaultErrorConstructors), "getKnownErrorConstructors");
|
|
29
|
+
const getErrorConstructor = /* @__PURE__ */ __name((name) => defaultErrorConstructors.get(name), "getErrorConstructor");
|
|
30
|
+
const isErrorLike = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && typeof value.name === "string" && typeof value.message === "string" && (getErrorConstructor(value.name) !== void 0 || value.name === "Error"), "isErrorLike");
|
|
31
|
+
|
|
32
|
+
export { addKnownErrorConstructor, getErrorConstructor, getKnownErrorConstructors, isErrorLike };
|
|
@@ -0,0 +1,39 @@
|
|
|
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 defaultErrorConstructors = /* @__PURE__ */ new Map([
|
|
8
|
+
["Error", Error],
|
|
9
|
+
["EvalError", EvalError],
|
|
10
|
+
["RangeError", RangeError],
|
|
11
|
+
["ReferenceError", ReferenceError],
|
|
12
|
+
["SyntaxError", SyntaxError],
|
|
13
|
+
["TypeError", TypeError],
|
|
14
|
+
["URIError", URIError]
|
|
15
|
+
]);
|
|
16
|
+
if (typeof AggregateError !== "undefined") {
|
|
17
|
+
defaultErrorConstructors.set("AggregateError", AggregateError);
|
|
18
|
+
}
|
|
19
|
+
const addKnownErrorConstructor = /* @__PURE__ */ __name((constructor, name) => {
|
|
20
|
+
let instance;
|
|
21
|
+
try {
|
|
22
|
+
instance = new constructor();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw new Error(`The error constructor "${constructor.name}" is not compatible`, { cause: error });
|
|
25
|
+
}
|
|
26
|
+
const resolvedName = name ?? instance.name;
|
|
27
|
+
if (defaultErrorConstructors.has(resolvedName)) {
|
|
28
|
+
throw new Error(`The error constructor "${resolvedName}" is already known.`);
|
|
29
|
+
}
|
|
30
|
+
defaultErrorConstructors.set(resolvedName, constructor);
|
|
31
|
+
}, "addKnownErrorConstructor");
|
|
32
|
+
const getKnownErrorConstructors = /* @__PURE__ */ __name(() => new Map(defaultErrorConstructors), "getKnownErrorConstructors");
|
|
33
|
+
const getErrorConstructor = /* @__PURE__ */ __name((name) => defaultErrorConstructors.get(name), "getErrorConstructor");
|
|
34
|
+
const isErrorLike = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && typeof value.name === "string" && typeof value.message === "string" && (getErrorConstructor(value.name) !== void 0 || value.name === "Error"), "isErrorLike");
|
|
35
|
+
|
|
36
|
+
exports.addKnownErrorConstructor = addKnownErrorConstructor;
|
|
37
|
+
exports.getErrorConstructor = getErrorConstructor;
|
|
38
|
+
exports.getKnownErrorConstructors = getKnownErrorConstructors;
|
|
39
|
+
exports.isErrorLike = isErrorLike;
|