mol_wire_lib 1.0.1293 → 1.0.1295

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/node.test.js CHANGED
@@ -2673,17 +2673,36 @@ var $;
2673
2673
  "use strict";
2674
2674
  var $;
2675
2675
  (function ($) {
2676
+ function cause_serialize(cause) {
2677
+ return JSON.stringify(cause, null, ' ')
2678
+ .replace(/\(/, '<')
2679
+ .replace(/\)/, ' >');
2680
+ }
2681
+ function frame_normalize(frame) {
2682
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
2683
+ .trim()
2684
+ .replace(/at /gm, ' at ')
2685
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
2686
+ }
2676
2687
  class $mol_error_mix extends AggregateError {
2677
2688
  cause;
2678
2689
  name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
2679
2690
  constructor(message, cause = {}, ...errors) {
2680
2691
  super(errors, message, { cause });
2681
2692
  this.cause = cause;
2682
- const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
2693
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
2694
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
2683
2695
  Object.defineProperty(this, 'stack', {
2684
- get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
2685
- .replace(/at /gm, ' at ')
2686
- .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
2696
+ get: () => stack_get() + '\n' + [
2697
+ this.cause ?? 'no cause',
2698
+ ...this.errors.flatMap(e => [
2699
+ e.stack,
2700
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
2701
+ ])
2702
+ ].map(frame_normalize).join('\n')
2703
+ });
2704
+ Object.defineProperty(this, 'cause', {
2705
+ get: () => cause
2687
2706
  });
2688
2707
  }
2689
2708
  static [Symbol.toPrimitive]() {