@visulima/error 6.0.0-alpha.2 → 6.0.0-alpha.4

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 CHANGED
@@ -1,3 +1,32 @@
1
+ ## @visulima/error [6.0.0-alpha.4](https://github.com/visulima/visulima/compare/@visulima/error@6.0.0-alpha.3...@visulima/error@6.0.0-alpha.4) (2026-01-17)
2
+
3
+ ### ⚠ BREAKING CHANGES
4
+
5
+ * **serialize:** Serialized errors now have all properties explicitly enumerable, which may affect code relying on property enumerability checks. ErrorProto properties are now non-enumerable.
6
+
7
+ ### Bug Fixes
8
+
9
+ * **serialize:** improve error serialization enumerability and circular reference handling ([41e2f0b](https://github.com/visulima/visulima/commit/41e2f0b2dd43b75ec4c44dda0bad3200319cd489))
10
+
11
+ ### Miscellaneous Chores
12
+
13
+ * **error:** update dependencies ([8dcc42c](https://github.com/visulima/visulima/commit/8dcc42cc1cbe6f3acceecb3360cb8dce0b99deb7))
14
+
15
+ ## @visulima/error [6.0.0-alpha.3](https://github.com/visulima/visulima/compare/@visulima/error@6.0.0-alpha.2...@visulima/error@6.0.0-alpha.3) (2025-12-27)
16
+
17
+ ### Bug Fixes
18
+
19
+ * **error:** update package files ([ea9d556](https://github.com/visulima/visulima/commit/ea9d55669d1f3e0d7902d931a82e0acd39081ea7))
20
+
21
+ ### Miscellaneous Chores
22
+
23
+ * fixed project.json names and schema path ([964722f](https://github.com/visulima/visulima/commit/964722f691db205c7edb9aa6db29e849a647500b))
24
+
25
+
26
+ ### Dependencies
27
+
28
+ * **@visulima/path:** upgraded to 3.0.0-alpha.4
29
+
1
30
  ## @visulima/error [6.0.0-alpha.2](https://github.com/visulima/visulima/compare/@visulima/error@6.0.0-alpha.1...@visulima/error@6.0.0-alpha.2) (2025-12-11)
2
31
 
3
32
  ### Bug Fixes
@@ -1,8 +1,8 @@
1
1
  export { default as captureRawStackTrace } from '../packem_shared/captureRawStackTrace-ySw7cU0U.js';
2
2
  export { default as getErrorCauses } from '../packem_shared/getErrorCauses-DpUsmuqw.js';
3
3
  export { renderError } from '../packem_shared/renderError-C30PRFtU.js';
4
- export { default as deserializeError } from '../packem_shared/deserializeError-CvSvGfXa.js';
4
+ export { default as deserializeError } from '../packem_shared/deserializeError-BsFrjsrV.js';
5
5
  export { addKnownErrorConstructor, isErrorLike } from '../packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
6
6
  export { default as NonError } from '../packem_shared/NonError-D5FGLYKY.js';
7
- export { serialize as serializeError } from '../packem_shared/serializeError-BZ62KiYZ.js';
7
+ export { serialize as serializeError } from '../packem_shared/serializeError-e9YW13-X.js';
8
8
  export { VisulimaError, isVisulimaError } from '../packem_shared/isVisulimaError-DA7QsCxH.js';
package/dist/index.js CHANGED
@@ -5,12 +5,12 @@ export { default as aiSolutionResponse } from './packem_shared/aiSolutionRespons
5
5
  export { default as errorHintFinder } from './packem_shared/errorHintFinder-DEaeRnRW.js';
6
6
  export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-C2F8rQ30.js';
7
7
  export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-ySw7cU0U.js';
8
- export { default as deserializeError } from './packem_shared/deserializeError-CvSvGfXa.js';
8
+ export { default as deserializeError } from './packem_shared/deserializeError-BsFrjsrV.js';
9
9
  export { default as getErrorCauses } from './packem_shared/getErrorCauses-DpUsmuqw.js';
10
10
  export { default as NonError } from './packem_shared/NonError-D5FGLYKY.js';
11
11
  export { default as parseStacktrace } from './packem_shared/parseStacktrace-oQvk7wYp.js';
12
12
  export { addKnownErrorConstructor, isErrorLike } from './packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
13
13
  export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-DA7QsCxH.js';
14
14
  export { renderError } from './packem_shared/renderError-C30PRFtU.js';
15
- export { serialize as serializeError } from './packem_shared/serializeError-BZ62KiYZ.js';
15
+ export { serialize as serializeError } from './packem_shared/serializeError-e9YW13-X.js';
16
16
  export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-D3_6oSWZ.js';
@@ -43,7 +43,14 @@ const reconstructError = (serialized, options, depth) => {
43
43
  };
44
44
  const deserializeValue = (value, options, depth) => {
45
45
  if (isPlainObject(value)) {
46
- return deserializePlainObject(value, options, depth);
46
+ if (isErrorLike(value)) {
47
+ return deserializePlainObject(value, options, depth);
48
+ }
49
+ const result = {};
50
+ for (const [key, value_] of Object.entries(value)) {
51
+ result[key] = deserializeValue(value_, options, depth + 1);
52
+ }
53
+ return result;
47
54
  }
48
55
  if (Array.isArray(value)) {
49
56
  return value.map((item) => deserializeValue(item, options, depth));
@@ -0,0 +1,224 @@
1
+ import { i as isPlainObject } from './index-y_UPkY2Z.js';
2
+
3
+ const ErrorProto = Object.create(
4
+ {},
5
+ {
6
+ cause: {
7
+ enumerable: false,
8
+ value: void 0,
9
+ writable: true
10
+ },
11
+ code: {
12
+ enumerable: true,
13
+ value: void 0,
14
+ writable: true
15
+ },
16
+ errors: {
17
+ enumerable: false,
18
+ value: void 0,
19
+ writable: true
20
+ },
21
+ message: {
22
+ enumerable: false,
23
+ value: void 0,
24
+ writable: true
25
+ },
26
+ name: {
27
+ enumerable: false,
28
+ value: void 0,
29
+ writable: true
30
+ },
31
+ stack: {
32
+ enumerable: false,
33
+ value: void 0,
34
+ writable: true
35
+ }
36
+ }
37
+ );
38
+
39
+ const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
40
+ const makePropertiesEnumerable = (object) => {
41
+ if (!object || typeof object !== "object") {
42
+ return;
43
+ }
44
+ const props = Object.getOwnPropertyNames(object);
45
+ for (const prop of props) {
46
+ const descriptor = Object.getOwnPropertyDescriptor(object, prop);
47
+ if (descriptor) {
48
+ if (!descriptor.enumerable) {
49
+ Object.defineProperty(object, prop, {
50
+ ...descriptor,
51
+ enumerable: true
52
+ });
53
+ }
54
+ if (descriptor.value && typeof descriptor.value === "object" && !Array.isArray(descriptor.value) && (Object.getPrototypeOf(descriptor.value) === Object.prototype || Object.getPrototypeOf(descriptor.value) === null)) {
55
+ makePropertiesEnumerable(descriptor.value);
56
+ }
57
+ }
58
+ }
59
+ };
60
+ const toJSON = (from) => {
61
+ toJsonWasCalled.add(from);
62
+ const json = from.toJSON();
63
+ toJsonWasCalled.delete(from);
64
+ if (json && typeof json === "object" && Object.isExtensible(json)) {
65
+ makePropertiesEnumerable(json);
66
+ }
67
+ return json;
68
+ };
69
+ const serializeValue = (value, seen, depth, options) => {
70
+ if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
71
+ return "[object Buffer]";
72
+ }
73
+ if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
74
+ return "[object Stream]";
75
+ }
76
+ if (value instanceof Error) {
77
+ if (seen.has(value)) {
78
+ return "[Circular]";
79
+ }
80
+ depth += 1;
81
+ return _serialize(value, options, seen, depth);
82
+ }
83
+ if (options.useToJSON && typeof value.toJSON === "function") {
84
+ return value.toJSON();
85
+ }
86
+ if (typeof value === "object" && value instanceof Date) {
87
+ return value.toISOString();
88
+ }
89
+ if (typeof value === "function") {
90
+ return `[Function: ${value.name || "anonymous"}]`;
91
+ }
92
+ if (typeof value === "bigint") {
93
+ return `${value}n`;
94
+ }
95
+ if (isPlainObject(value)) {
96
+ if (options.maxDepth !== void 0 && options.maxDepth !== Number.POSITIVE_INFINITY && depth + 1 >= options.maxDepth) {
97
+ return {};
98
+ }
99
+ depth += 1;
100
+ const plainObject = {};
101
+ for (const key in value) {
102
+ plainObject[key] = serializeValue(value[key], seen, depth, options);
103
+ }
104
+ return plainObject;
105
+ }
106
+ try {
107
+ return value;
108
+ } catch {
109
+ return "[Not Available]";
110
+ }
111
+ };
112
+ const _serialize = (error, options, seen, depth) => {
113
+ seen.add(error);
114
+ if (options.maxDepth === 0) {
115
+ return {};
116
+ }
117
+ if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
118
+ return toJSON(error);
119
+ }
120
+ const protoError = Object.create(ErrorProto);
121
+ Object.defineProperty(protoError, "name", {
122
+ configurable: true,
123
+ enumerable: true,
124
+ value: Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name,
125
+ writable: true
126
+ });
127
+ Object.defineProperty(protoError, "message", {
128
+ configurable: true,
129
+ enumerable: true,
130
+ value: error.message,
131
+ writable: true
132
+ });
133
+ Object.defineProperty(protoError, "stack", {
134
+ configurable: true,
135
+ enumerable: true,
136
+ value: error.stack,
137
+ writable: true
138
+ });
139
+ if (Array.isArray(error.errors)) {
140
+ const aggregateErrors = [];
141
+ for (const aggregateError of error.errors) {
142
+ if (!(aggregateError instanceof Error)) {
143
+ throw new TypeError("All errors in the 'errors' property must be instances of Error");
144
+ }
145
+ if (seen.has(aggregateError)) {
146
+ Object.defineProperty(protoError, "errors", {
147
+ configurable: true,
148
+ enumerable: true,
149
+ value: [],
150
+ writable: true
151
+ });
152
+ return protoError;
153
+ }
154
+ aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
155
+ }
156
+ Object.defineProperty(protoError, "errors", {
157
+ configurable: true,
158
+ enumerable: true,
159
+ value: aggregateErrors,
160
+ writable: true
161
+ });
162
+ }
163
+ if (error.cause !== void 0 && error.cause !== null) {
164
+ if (error.cause instanceof Error) {
165
+ if (seen.has(error.cause)) {
166
+ Object.defineProperty(protoError, "cause", {
167
+ configurable: true,
168
+ enumerable: true,
169
+ value: "[Circular]",
170
+ writable: true
171
+ });
172
+ } else {
173
+ Object.defineProperty(protoError, "cause", {
174
+ configurable: true,
175
+ enumerable: true,
176
+ value: _serialize(error.cause, options, seen, depth),
177
+ writable: true
178
+ });
179
+ }
180
+ } else {
181
+ const serializedCause = serializeValue(error.cause, seen, depth, options);
182
+ Object.defineProperty(protoError, "cause", {
183
+ configurable: true,
184
+ enumerable: true,
185
+ value: serializedCause,
186
+ writable: true
187
+ });
188
+ }
189
+ }
190
+ for (const key in error) {
191
+ if (key === "name" || key === "message" || key === "stack" || key === "cause" || key === "errors") {
192
+ continue;
193
+ }
194
+ const value = error[key];
195
+ const serializedValue = serializeValue(value, seen, depth, options);
196
+ Object.defineProperty(protoError, key, {
197
+ configurable: true,
198
+ enumerable: true,
199
+ value: serializedValue,
200
+ writable: true
201
+ });
202
+ }
203
+ if (Array.isArray(options.exclude) && options.exclude.length > 0) {
204
+ for (const key of options.exclude) {
205
+ try {
206
+ delete protoError[key];
207
+ } catch {
208
+ }
209
+ }
210
+ }
211
+ return protoError;
212
+ };
213
+ const serialize = (error, options = {}) => _serialize(
214
+ error,
215
+ {
216
+ exclude: options.exclude ?? [],
217
+ maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
218
+ useToJSON: options.useToJSON ?? false
219
+ },
220
+ /* @__PURE__ */ new Set(),
221
+ 0
222
+ );
223
+
224
+ export { serialize };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/error",
3
- "version": "6.0.0-alpha.2",
3
+ "version": "6.0.0-alpha.4",
4
4
  "description": "Error with more than just a message, stacktrace parsing.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -1,142 +0,0 @@
1
- import { i as isPlainObject } from './index-y_UPkY2Z.js';
2
-
3
- const ErrorProto = Object.create(
4
- {},
5
- {
6
- cause: {
7
- enumerable: true,
8
- value: void 0,
9
- writable: true
10
- },
11
- code: {
12
- enumerable: true,
13
- value: void 0,
14
- writable: true
15
- },
16
- errors: {
17
- enumerable: true,
18
- value: void 0,
19
- writable: true
20
- },
21
- message: {
22
- enumerable: true,
23
- value: void 0,
24
- writable: true
25
- },
26
- name: {
27
- enumerable: true,
28
- value: void 0,
29
- writable: true
30
- },
31
- stack: {
32
- enumerable: true,
33
- value: void 0,
34
- writable: true
35
- }
36
- }
37
- );
38
-
39
- const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
40
- const toJSON = (from) => {
41
- toJsonWasCalled.add(from);
42
- const json = from.toJSON();
43
- toJsonWasCalled.delete(from);
44
- return json;
45
- };
46
- const serializeValue = (value, seen, depth, options) => {
47
- if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
48
- return "[object Buffer]";
49
- }
50
- if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
51
- return "[object Stream]";
52
- }
53
- if (value instanceof Error) {
54
- if (seen.includes(value)) {
55
- return "[Circular]";
56
- }
57
- depth += 1;
58
- return _serialize(value, options, seen, depth);
59
- }
60
- if (options.useToJSON && typeof value.toJSON === "function") {
61
- return value.toJSON();
62
- }
63
- if (typeof value === "object" && value instanceof Date) {
64
- return value.toISOString();
65
- }
66
- if (typeof value === "function") {
67
- return `[Function: ${value.name || "anonymous"}]`;
68
- }
69
- if (isPlainObject(value)) {
70
- depth += 1;
71
- if (options.maxDepth && depth >= options.maxDepth) {
72
- return {};
73
- }
74
- const plainObject = {};
75
- for (const key in value) {
76
- plainObject[key] = serializeValue(value[key], seen, depth, options);
77
- }
78
- return plainObject;
79
- }
80
- try {
81
- return value;
82
- } catch {
83
- return "[Not Available]";
84
- }
85
- };
86
- const _serialize = (error, options, seen, depth) => {
87
- seen.push(error);
88
- if (options.maxDepth === 0) {
89
- return {};
90
- }
91
- if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
92
- return toJSON(error);
93
- }
94
- const protoError = Object.create(ErrorProto);
95
- protoError.name = Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name;
96
- protoError.message = error.message;
97
- protoError.stack = error.stack;
98
- if (Array.isArray(error.errors)) {
99
- const aggregateErrors = [];
100
- for (const aggregateError of error.errors) {
101
- if (!(aggregateError instanceof Error)) {
102
- throw new TypeError("All errors in the 'errors' property must be instances of Error");
103
- }
104
- if (seen.includes(aggregateError)) {
105
- protoError.errors = [];
106
- return protoError;
107
- }
108
- aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
109
- }
110
- protoError.errors = aggregateErrors;
111
- }
112
- if (error.cause instanceof Error && !seen.includes(error.cause)) {
113
- protoError.cause = _serialize(error.cause, options, seen, depth);
114
- }
115
- for (const key in error) {
116
- if (protoError[key] === void 0) {
117
- const value = error[key];
118
- protoError[key] = serializeValue(value, seen, depth, options);
119
- }
120
- }
121
- if (Array.isArray(options.exclude) && options.exclude.length > 0) {
122
- for (const key of options.exclude) {
123
- try {
124
- delete protoError[key];
125
- } catch {
126
- }
127
- }
128
- }
129
- return protoError;
130
- };
131
- const serialize = (error, options = {}) => _serialize(
132
- error,
133
- {
134
- exclude: options.exclude ?? [],
135
- maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
136
- useToJSON: options.useToJSON ?? false
137
- },
138
- [],
139
- 0
140
- );
141
-
142
- export { serialize };