mol_mutable 0.0.789 → 0.0.790

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
@@ -345,17 +345,36 @@ var $;
345
345
  "use strict";
346
346
  var $;
347
347
  (function ($) {
348
+ function cause_serialize(cause) {
349
+ return JSON.stringify(cause, null, ' ')
350
+ .replace(/\(/, '<')
351
+ .replace(/\)/, ' >');
352
+ }
353
+ function frame_normalize(frame) {
354
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
355
+ .trim()
356
+ .replace(/at /gm, ' at ')
357
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
358
+ }
348
359
  class $mol_error_mix extends AggregateError {
349
360
  cause;
350
361
  name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
351
362
  constructor(message, cause = {}, ...errors) {
352
363
  super(errors, message, { cause });
353
364
  this.cause = cause;
354
- const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
365
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
366
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
355
367
  Object.defineProperty(this, 'stack', {
356
- 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()
357
- .replace(/at /gm, ' at ')
358
- .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
368
+ get: () => stack_get() + '\n' + [
369
+ this.cause ?? 'no cause',
370
+ ...this.errors.flatMap(e => [
371
+ e.stack,
372
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
373
+ ])
374
+ ].map(frame_normalize).join('\n')
375
+ });
376
+ Object.defineProperty(this, 'cause', {
377
+ get: () => cause
359
378
  });
360
379
  }
361
380
  static [Symbol.toPrimitive]() {