@devp0nt/error0 1.0.0-next.45 → 1.0.0-next.47

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 (57) hide show
  1. package/dist/cjs/index.cjs +80 -64
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +32 -22
  4. package/dist/cjs/plugins/cause-serialize.cjs +38 -0
  5. package/dist/cjs/plugins/cause-serialize.cjs.map +1 -0
  6. package/dist/cjs/plugins/cause-serialize.d.cts +5 -0
  7. package/dist/cjs/plugins/expected.cjs +49 -0
  8. package/dist/cjs/plugins/expected.cjs.map +1 -0
  9. package/dist/cjs/plugins/expected.d.cts +5 -0
  10. package/dist/cjs/plugins/message-merge.cjs +36 -0
  11. package/dist/cjs/plugins/message-merge.cjs.map +1 -0
  12. package/dist/cjs/plugins/message-merge.d.cts +5 -0
  13. package/dist/cjs/plugins/meta.cjs +73 -0
  14. package/dist/cjs/plugins/meta.cjs.map +1 -0
  15. package/dist/cjs/plugins/meta.d.cts +5 -0
  16. package/dist/cjs/plugins/stack-merge.cjs +39 -0
  17. package/dist/cjs/plugins/stack-merge.cjs.map +1 -0
  18. package/dist/cjs/plugins/stack-merge.d.cts +5 -0
  19. package/dist/cjs/plugins/tags.cjs +48 -0
  20. package/dist/cjs/plugins/tags.cjs.map +1 -0
  21. package/dist/cjs/plugins/tags.d.cts +5 -0
  22. package/dist/esm/index.d.ts +32 -22
  23. package/dist/esm/index.js +80 -64
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/plugins/cause-serialize.d.ts +5 -0
  26. package/dist/esm/plugins/cause-serialize.js +14 -0
  27. package/dist/esm/plugins/cause-serialize.js.map +1 -0
  28. package/dist/esm/plugins/expected.d.ts +5 -0
  29. package/dist/esm/plugins/expected.js +25 -0
  30. package/dist/esm/plugins/expected.js.map +1 -0
  31. package/dist/esm/plugins/message-merge.d.ts +5 -0
  32. package/dist/esm/plugins/message-merge.js +12 -0
  33. package/dist/esm/plugins/message-merge.js.map +1 -0
  34. package/dist/esm/plugins/meta.d.ts +5 -0
  35. package/dist/esm/plugins/meta.js +49 -0
  36. package/dist/esm/plugins/meta.js.map +1 -0
  37. package/dist/esm/plugins/stack-merge.d.ts +5 -0
  38. package/dist/esm/plugins/stack-merge.js +15 -0
  39. package/dist/esm/plugins/stack-merge.js.map +1 -0
  40. package/dist/esm/plugins/tags.d.ts +5 -0
  41. package/dist/esm/plugins/tags.js +24 -0
  42. package/dist/esm/plugins/tags.js.map +1 -0
  43. package/package.json +9 -1
  44. package/src/index.test.ts +77 -100
  45. package/src/index.ts +173 -120
  46. package/src/plugins/cause-serialize.test.ts +51 -0
  47. package/src/plugins/cause-serialize.ts +11 -0
  48. package/src/plugins/expected.test.ts +47 -0
  49. package/src/plugins/expected.ts +25 -0
  50. package/src/plugins/message-merge.test.ts +32 -0
  51. package/src/plugins/message-merge.ts +15 -0
  52. package/src/plugins/meta.test.ts +32 -0
  53. package/src/plugins/meta.ts +53 -0
  54. package/src/plugins/stack-merge.test.ts +64 -0
  55. package/src/plugins/stack-merge.ts +16 -0
  56. package/src/plugins/tags.test.ts +22 -0
  57. package/src/plugins/tags.ts +21 -0
@@ -34,18 +34,30 @@ type ErrorPluginPropOptions<TInputValue = undefined, TOutputValue = unknown, TEr
34
34
  type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
35
35
  type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
36
36
  type ErrorPluginAdaptFn<TError extends Error0 = Error0, TOutputProps extends Record<string, unknown> = Record<never, never>> = ((error: TError) => void) | ((error: TError) => ErrorPluginAdaptResult<TOutputProps>);
37
- type ErrorPluginStackSerialize<TError extends Error0> = ((options: {
37
+ type ErrorPluginStackSerialize<TError extends Error0> = (options: {
38
38
  value: string | undefined;
39
39
  error: TError;
40
40
  isPublic: boolean;
41
- }) => unknown) | boolean | 'merge';
42
- type ErrorPluginStack<TError extends Error0 = Error0> = ErrorPluginStackSerialize<TError>;
43
- type ErrorPluginCauseSerialize<TError extends Error0> = ((options: {
41
+ }) => unknown;
42
+ type ErrorPluginStack<TError extends Error0 = Error0> = {
43
+ serialize: ErrorPluginStackSerialize<TError>;
44
+ };
45
+ type ErrorPluginCauseSerialize<TError extends Error0> = (options: {
44
46
  value: unknown;
45
47
  error: TError;
46
48
  isPublic: boolean;
47
- }) => unknown) | boolean;
48
- type ErrorPluginCause<TError extends Error0 = Error0> = ErrorPluginCauseSerialize<TError>;
49
+ }) => unknown;
50
+ type ErrorPluginCause<TError extends Error0 = Error0> = {
51
+ serialize: ErrorPluginCauseSerialize<TError>;
52
+ };
53
+ type ErrorPluginMessageSerialize<TError extends Error0> = (options: {
54
+ value: string;
55
+ error: TError;
56
+ isPublic: boolean;
57
+ }) => unknown;
58
+ type ErrorPluginMessage<TError extends Error0 = Error0> = {
59
+ serialize: ErrorPluginMessageSerialize<TError>;
60
+ };
49
61
  type ErrorMethodRecord = {
50
62
  args: unknown[];
51
63
  output: unknown;
@@ -62,6 +74,7 @@ type ErrorPlugin<TProps extends ErrorPluginProps = Record<never, never>, TMethod
62
74
  adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>;
63
75
  stack?: ErrorPluginStack;
64
76
  cause?: ErrorPluginCause;
77
+ message?: ErrorPluginMessage;
65
78
  };
66
79
  type AddPropToPluginProps<TProps extends ErrorPluginProps, TKey extends string, TInputValue, TOutputValue, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>;
67
80
  type AddMethodToPluginMethods<TMethods extends ErrorPluginMethods, TKey extends string, TArgs extends unknown[], TOutputValue> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>;
@@ -148,9 +161,7 @@ type PluginsMapOf<TClass> = TClass extends {
148
161
  __pluginsMap?: infer TPluginsMap;
149
162
  } ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
150
163
  type PluginsMapOfInstance<TInstance> = TInstance extends {
151
- constructor: {
152
- __pluginsMap?: infer TPluginsMap;
153
- };
164
+ __pluginsMap?: infer TPluginsMap;
154
165
  } ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
155
166
  type PluginsMapFromParts<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>;
156
167
  type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TMap>;
@@ -168,17 +179,23 @@ declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never
168
179
  adapt(value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
169
180
  stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
170
181
  cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
182
+ message(value: ErrorPluginMessage<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
171
183
  use<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>;
172
184
  use<TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>>;
173
185
  use(kind: 'adapt', value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
174
186
  use(kind: 'stack', value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
175
187
  use(kind: 'cause', value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
188
+ use(kind: 'message', value: ErrorPluginMessage<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
176
189
  }
177
190
  type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
178
- new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
191
+ new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap> & {
192
+ readonly __pluginsMap?: TPluginsMap;
193
+ };
179
194
  new (input: {
180
195
  message: string;
181
- } & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
196
+ } & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap> & {
197
+ readonly __pluginsMap?: TPluginsMap;
198
+ };
182
199
  readonly __pluginsMap?: TPluginsMap;
183
200
  from: (error: unknown) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
184
201
  resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>;
@@ -188,11 +205,6 @@ type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
188
205
  <TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey): ErrorOwnProps<TPluginsMap>[TKey];
189
206
  };
190
207
  flow: <TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>;
191
- prop: <TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>) => ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>;
192
- method: <TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
193
- adapt: (value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>) => ClassError0<TPluginsMap>;
194
- stack: (value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>;
195
- cause: (value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>;
196
208
  use: {
197
209
  <TBuilder extends PluginError0>(plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<TPluginsMap, PluginOfBuilder<TBuilder>>>;
198
210
  <TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>;
@@ -200,11 +212,13 @@ type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
200
212
  (kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>): ClassError0<TPluginsMap>;
201
213
  (kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>;
202
214
  (kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>;
215
+ (kind: 'message', value: ErrorPluginMessage<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>;
203
216
  };
204
217
  plugin: () => PluginError0;
205
218
  } & ErrorStaticMethods<TPluginsMap>;
206
219
  declare class Error0 extends Error {
207
220
  static readonly __pluginsMap?: EmptyPluginsMap;
221
+ readonly __pluginsMap?: EmptyPluginsMap;
208
222
  protected static _plugins: ErrorPlugin[];
209
223
  private static readonly _emptyPlugin;
210
224
  private static _getResolvedPlugin;
@@ -240,20 +254,16 @@ declare class Error0 extends Error {
240
254
  private static _extractMessage;
241
255
  private static _useWithPlugin;
242
256
  private static _pluginFromBuilder;
243
- static prop<TThis extends typeof Error0, TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(this: TThis, key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>;
244
- static method<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(this: TThis, key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>;
245
- static adapt<TThis extends typeof Error0>(this: TThis, value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
246
- static stack<TThis extends typeof Error0>(this: TThis, value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
247
- static cause<TThis extends typeof Error0>(this: TThis, value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
248
257
  static use<TThis extends typeof Error0, TBuilder extends PluginError0>(this: TThis, plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>;
249
258
  static use<TThis extends typeof Error0, TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(this: TThis, kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>;
250
259
  static use<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(this: TThis, kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>;
251
260
  static use<TThis extends typeof Error0>(this: TThis, kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
252
261
  static use<TThis extends typeof Error0>(this: TThis, kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
253
262
  static use<TThis extends typeof Error0>(this: TThis, kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
263
+ static use<TThis extends typeof Error0>(this: TThis, kind: 'message', value: ErrorPluginMessage<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
254
264
  static plugin(): PluginError0;
255
265
  static serialize(error: unknown, isPublic?: boolean): Record<string, unknown>;
256
266
  serialize(isPublic?: boolean): Record<string, unknown>;
257
267
  }
258
268
 
259
- export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
269
+ export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseSerialize, type ErrorPluginMessage, type ErrorPluginMessageSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const RESERVED_STACK_PROP_ERROR = 'Error0: "stack" is a reserved prop key. Use .stack(...) plugin API instead';
2
+ const RESERVED_MESSAGE_PROP_ERROR = 'Error0: "message" is a reserved prop key. Use .message(...) plugin API instead';
2
3
  class PluginError0 {
3
4
  _plugin;
4
5
  Infer = void 0;
@@ -8,7 +9,8 @@ class PluginError0 {
8
9
  methods: { ...plugin?.methods ?? {} },
9
10
  adapt: [...plugin?.adapt ?? []],
10
11
  stack: plugin?.stack,
11
- cause: plugin?.cause
12
+ cause: plugin?.cause,
13
+ message: plugin?.message
12
14
  };
13
15
  }
14
16
  prop(key, value) {
@@ -26,17 +28,24 @@ class PluginError0 {
26
28
  cause(value) {
27
29
  return this.use("cause", value);
28
30
  }
31
+ message(value) {
32
+ return this.use("message", value);
33
+ }
29
34
  use(kind, keyOrValue, value) {
30
35
  const nextProps = { ...this._plugin.props ?? {} };
31
36
  const nextMethods = { ...this._plugin.methods ?? {} };
32
37
  const nextAdapt = [...this._plugin.adapt ?? []];
33
38
  let nextStack = this._plugin.stack;
34
39
  let nextCause = this._plugin.cause;
40
+ let nextMessage = this._plugin.message;
35
41
  if (kind === "prop") {
36
42
  const key = keyOrValue;
37
43
  if (key === "stack") {
38
44
  throw new Error(RESERVED_STACK_PROP_ERROR);
39
45
  }
46
+ if (key === "message") {
47
+ throw new Error(RESERVED_MESSAGE_PROP_ERROR);
48
+ }
40
49
  if (value === void 0) {
41
50
  throw new Error('PluginError0.use("prop", key, value) requires value');
42
51
  }
@@ -51,27 +60,32 @@ class PluginError0 {
51
60
  nextAdapt.push(keyOrValue);
52
61
  } else if (kind === "stack") {
53
62
  nextStack = keyOrValue;
54
- } else {
63
+ } else if (kind === "cause") {
55
64
  nextCause = keyOrValue;
65
+ } else {
66
+ nextMessage = keyOrValue;
56
67
  }
57
68
  return new PluginError0({
58
69
  props: nextProps,
59
70
  methods: nextMethods,
60
71
  adapt: nextAdapt,
61
72
  stack: nextStack,
62
- cause: nextCause
73
+ cause: nextCause,
74
+ message: nextMessage
63
75
  });
64
76
  }
65
77
  }
66
78
  class Error0 extends Error {
67
79
  static __pluginsMap;
80
+ __pluginsMap;
68
81
  static _plugins = [];
69
82
  static _emptyPlugin = {
70
83
  props: {},
71
84
  methods: {},
72
85
  adapt: [],
73
86
  stack: void 0,
74
- cause: void 0
87
+ cause: void 0,
88
+ message: void 0
75
89
  };
76
90
  static _getResolvedPlugin() {
77
91
  const resolved = {
@@ -83,6 +97,9 @@ class Error0 extends Error {
83
97
  if (plugin.props && "stack" in plugin.props) {
84
98
  throw new Error(RESERVED_STACK_PROP_ERROR);
85
99
  }
100
+ if (plugin.props && "message" in plugin.props) {
101
+ throw new Error(RESERVED_MESSAGE_PROP_ERROR);
102
+ }
86
103
  Object.assign(resolved.props, plugin.props ?? this._emptyPlugin.props);
87
104
  Object.assign(resolved.methods, plugin.methods ?? this._emptyPlugin.methods);
88
105
  resolved.adapt.push(...plugin.adapt ?? this._emptyPlugin.adapt);
@@ -92,6 +109,9 @@ class Error0 extends Error {
92
109
  if (typeof plugin.cause !== "undefined") {
93
110
  resolved.cause = plugin.cause;
94
111
  }
112
+ if (typeof plugin.message !== "undefined") {
113
+ resolved.message = plugin.message;
114
+ }
95
115
  }
96
116
  return resolved;
97
117
  }
@@ -287,8 +307,7 @@ class Error0 extends Error {
287
307
  console.error(`Error0: failed to deserialize property ${key}`, errorRecord);
288
308
  }
289
309
  }
290
- const stackPlugin = plugin.stack;
291
- if (stackPlugin !== false && "stack" in errorRecord) {
310
+ if ("stack" in errorRecord) {
292
311
  try {
293
312
  if (typeof errorRecord.stack === "string") {
294
313
  recreated.stack = errorRecord.stack;
@@ -297,8 +316,8 @@ class Error0 extends Error {
297
316
  console.error("Error0: failed to deserialize stack", errorRecord);
298
317
  }
299
318
  }
300
- const causePlugin = plugin.cause ?? false;
301
- if (causePlugin && "cause" in errorRecord) {
319
+ const causePlugin = plugin.cause;
320
+ if (causePlugin?.serialize && "cause" in errorRecord) {
302
321
  try {
303
322
  if (this.isSerialized(errorRecord.cause)) {
304
323
  ;
@@ -353,24 +372,10 @@ class Error0 extends Error {
353
372
  methods: { ...pluginRecord._plugin.methods ?? {} },
354
373
  adapt: [...pluginRecord._plugin.adapt ?? []],
355
374
  stack: pluginRecord._plugin.stack,
356
- cause: pluginRecord._plugin.cause
375
+ cause: pluginRecord._plugin.cause,
376
+ message: pluginRecord._plugin.message
357
377
  };
358
378
  }
359
- static prop(key, value) {
360
- return this.use("prop", key, value);
361
- }
362
- static method(key, value) {
363
- return this.use("method", key, value);
364
- }
365
- static adapt(value) {
366
- return this.use("adapt", value);
367
- }
368
- static stack(value) {
369
- return this.use("stack", value);
370
- }
371
- static cause(value) {
372
- return this.use("cause", value);
373
- }
374
379
  static use(first, key, value) {
375
380
  if (first instanceof PluginError0) {
376
381
  return this._useWithPlugin(this._pluginFromBuilder(first));
@@ -379,8 +384,8 @@ class Error0 extends Error {
379
384
  if (typeof key === "undefined") {
380
385
  throw new Error('Error0.use("stack", value) requires stack plugin value');
381
386
  }
382
- if (key !== "merge" && typeof key !== "boolean" && typeof key !== "function") {
383
- throw new Error('Error0.use("stack", value) expects function | boolean | "merge"');
387
+ if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
388
+ throw new Error('Error0.use("stack", value) expects { serialize: function }');
384
389
  }
385
390
  return this._useWithPlugin({
386
391
  stack: key
@@ -390,13 +395,24 @@ class Error0 extends Error {
390
395
  if (typeof key === "undefined") {
391
396
  throw new Error('Error0.use("cause", value) requires cause plugin value');
392
397
  }
393
- if (typeof key !== "boolean" && typeof key !== "function") {
394
- throw new Error('Error0.use("cause", value) expects function | boolean');
398
+ if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
399
+ throw new Error('Error0.use("cause", value) expects { serialize: function }');
395
400
  }
396
401
  return this._useWithPlugin({
397
402
  cause: key
398
403
  });
399
404
  }
405
+ if (first === "message") {
406
+ if (typeof key === "undefined") {
407
+ throw new Error('Error0.use("message", value) requires message plugin value');
408
+ }
409
+ if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
410
+ throw new Error('Error0.use("message", value) expects { serialize: function }');
411
+ }
412
+ return this._useWithPlugin({
413
+ message: key
414
+ });
415
+ }
400
416
  if (first === "adapt") {
401
417
  if (typeof key !== "function") {
402
418
  throw new Error('Error0.use("adapt", value) requires adapt function');
@@ -412,6 +428,9 @@ class Error0 extends Error {
412
428
  if (key === "stack") {
413
429
  throw new Error(RESERVED_STACK_PROP_ERROR);
414
430
  }
431
+ if (key === "message") {
432
+ throw new Error(RESERVED_MESSAGE_PROP_ERROR);
433
+ }
415
434
  return this._useWithPlugin({
416
435
  props: { [key]: value }
417
436
  });
@@ -427,13 +446,23 @@ class Error0 extends Error {
427
446
  const error0 = this.from(error);
428
447
  const resolvedProps = this.resolve(error0);
429
448
  const resolvedRecord = resolvedProps;
449
+ const plugin = this._getResolvedPlugin();
450
+ const messagePlugin = plugin.message;
451
+ let serializedMessage = error0.message;
452
+ try {
453
+ if (messagePlugin) {
454
+ serializedMessage = messagePlugin.serialize({ value: error0.message, error: error0, isPublic });
455
+ }
456
+ } catch {
457
+ console.error("Error0: failed to serialize message", error0);
458
+ serializedMessage = error0.message;
459
+ }
430
460
  const json = {
431
461
  name: error0.name,
432
- message: error0.message
462
+ message: serializedMessage
433
463
  // we do not serialize causes, it is enough that we have floated props and adapt helper
434
464
  // cause: error0.cause,
435
465
  };
436
- const plugin = this._getResolvedPlugin();
437
466
  const propsEntries = Object.entries(plugin.props);
438
467
  for (const [key, prop] of propsEntries) {
439
468
  if (prop.serialize === false) {
@@ -449,43 +478,30 @@ class Error0 extends Error {
449
478
  console.error(`Error0: failed to serialize property ${key}`, resolvedRecord);
450
479
  }
451
480
  }
452
- const stackSerialize = plugin.stack;
453
- if (stackSerialize !== false) {
454
- try {
455
- let serializedStack;
456
- if (stackSerialize === "merge") {
457
- serializedStack = error0.causes().map((cause) => {
458
- return cause instanceof Error ? cause.stack : void 0;
459
- }).filter((value) => typeof value === "string").join("\n");
460
- } else if (typeof stackSerialize === "function") {
461
- serializedStack = stackSerialize({ value: error0.stack, error: error0, isPublic });
462
- } else {
463
- serializedStack = error0.stack;
464
- }
465
- if (serializedStack !== void 0) {
466
- json.stack = serializedStack;
467
- }
468
- } catch {
469
- console.error("Error0: failed to serialize stack", error0);
481
+ const stackPlugin = plugin.stack;
482
+ try {
483
+ let serializedStack;
484
+ if (stackPlugin) {
485
+ serializedStack = stackPlugin.serialize({ value: error0.stack, error: error0, isPublic });
486
+ } else {
487
+ serializedStack = error0.stack;
470
488
  }
489
+ if (serializedStack !== void 0) {
490
+ json.stack = serializedStack;
491
+ }
492
+ } catch {
493
+ console.error("Error0: failed to serialize stack", error0);
471
494
  }
472
- const causeSerialize = plugin.cause ?? false;
473
- if (causeSerialize) {
495
+ const causePlugin = plugin.cause;
496
+ if (causePlugin?.serialize) {
474
497
  try {
475
- if (causeSerialize === true) {
476
- const causeValue = error0.cause;
477
- if (this.is(causeValue)) {
478
- json.cause = this.serialize(causeValue, isPublic);
479
- }
480
- } else {
481
- const serializedCause = causeSerialize({
482
- value: error0.cause,
483
- error: error0,
484
- isPublic
485
- });
486
- if (serializedCause !== void 0) {
487
- json.cause = serializedCause;
488
- }
498
+ const serializedCause = causePlugin.serialize({
499
+ value: error0.cause,
500
+ error: error0,
501
+ isPublic
502
+ });
503
+ if (serializedCause !== void 0) {
504
+ json.cause = serializedCause;
489
505
  }
490
506
  } catch {
491
507
  console.error("Error0: failed to serialize cause", error0);