mol_view_tree2_lib 1.0.142 → 1.0.144

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/web.mjs CHANGED
@@ -4678,6 +4678,93 @@ var $;
4678
4678
  })($mol_rest_code = $.$mol_rest_code || ($.$mol_rest_code = {}));
4679
4679
  })($ || ($ = {}));
4680
4680
 
4681
+ ;
4682
+ "use strict";
4683
+ var $;
4684
+ (function ($) {
4685
+ function cause_serialize(cause) {
4686
+ return JSON.stringify(cause, null, ' ')
4687
+ .replace(/\(/, '<')
4688
+ .replace(/\)/, ' >');
4689
+ }
4690
+ function frame_normalize(frame) {
4691
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
4692
+ .trim()
4693
+ .replace(/at /gm, ' at ')
4694
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
4695
+ }
4696
+ class $mol_error_mix extends AggregateError {
4697
+ cause;
4698
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
4699
+ constructor(message, cause = {}, ...errors) {
4700
+ super(errors, message, { cause });
4701
+ this.cause = cause;
4702
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
4703
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
4704
+ Object.defineProperty(this, 'stack', {
4705
+ get: () => stack_get() + '\n' + [
4706
+ this.cause ?? 'no cause',
4707
+ ...this.errors.flatMap(e => [
4708
+ String(e.stack),
4709
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
4710
+ ])
4711
+ ].map(frame_normalize).join('\n')
4712
+ });
4713
+ Object.defineProperty(this, 'cause', {
4714
+ get: () => cause
4715
+ });
4716
+ }
4717
+ static [Symbol.toPrimitive]() {
4718
+ return this.toString();
4719
+ }
4720
+ static toString() {
4721
+ return $$.$mol_func_name(this);
4722
+ }
4723
+ static make(...params) {
4724
+ return new this(...params);
4725
+ }
4726
+ }
4727
+ $.$mol_error_mix = $mol_error_mix;
4728
+ })($ || ($ = {}));
4729
+
4730
+ ;
4731
+ "use strict";
4732
+ var $;
4733
+ (function ($) {
4734
+ function pass(data) {
4735
+ return data;
4736
+ }
4737
+ function $mol_error_fence(task, fallback, loading = pass) {
4738
+ try {
4739
+ return task();
4740
+ }
4741
+ catch (error) {
4742
+ let normalized;
4743
+ try {
4744
+ normalized = $mol_promise_like(error) ? loading(error) : fallback(error);
4745
+ }
4746
+ catch (sub_error) {
4747
+ normalized = $mol_promise_like(sub_error) ? sub_error : new $mol_error_mix(sub_error.message, { error }, sub_error);
4748
+ }
4749
+ if (normalized instanceof Error || $mol_promise_like(normalized)) {
4750
+ $mol_fail_hidden(normalized);
4751
+ }
4752
+ return normalized;
4753
+ }
4754
+ }
4755
+ $.$mol_error_fence = $mol_error_fence;
4756
+ })($ || ($ = {}));
4757
+
4758
+ ;
4759
+ "use strict";
4760
+ var $;
4761
+ (function ($) {
4762
+ function $mol_error_enriched(cause, cb) {
4763
+ return $mol_error_fence(cb, e => new $mol_error_mix(e.message, cause, e));
4764
+ }
4765
+ $.$mol_error_enriched = $mol_error_enriched;
4766
+ })($ || ($ = {}));
4767
+
4681
4768
  ;
4682
4769
  "use strict";
4683
4770
  var $;
@@ -4730,13 +4817,13 @@ var $;
4730
4817
  return decoder.decode(buffer);
4731
4818
  }
4732
4819
  json() {
4733
- return $mol_wire_sync(this.native).json();
4820
+ return $mol_error_enriched(this, () => $mol_wire_sync(this.native).json());
4734
4821
  }
4735
4822
  blob() {
4736
- return $mol_wire_sync(this.native).blob();
4823
+ return $mol_error_enriched(this, () => $mol_wire_sync(this.native).blob());
4737
4824
  }
4738
4825
  buffer() {
4739
- return $mol_wire_sync(this.native).arrayBuffer();
4826
+ return $mol_error_enriched(this, () => $mol_wire_sync(this.native).arrayBuffer());
4740
4827
  }
4741
4828
  xml() {
4742
4829
  return $mol_dom_parse(this.text(), 'application/xml');
package/web.test.js CHANGED
@@ -6051,6 +6051,39 @@ var $;
6051
6051
  });
6052
6052
  })($ || ($ = {}));
6053
6053
 
6054
+ ;
6055
+ "use strict";
6056
+ var $;
6057
+ (function ($) {
6058
+ $mol_test({
6059
+ 'auto name'() {
6060
+ class Invalid extends $mol_error_mix {
6061
+ }
6062
+ const mix = new Invalid('foo');
6063
+ $mol_assert_equal(mix.name, 'Invalid_Error');
6064
+ },
6065
+ 'simpe mix'() {
6066
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
6067
+ $mol_assert_equal(mix.message, 'foo');
6068
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
6069
+ },
6070
+ 'provide additional info'() {
6071
+ class Invalid extends $mol_error_mix {
6072
+ }
6073
+ const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
6074
+ const hints = [];
6075
+ if (mix instanceof $mol_error_mix) {
6076
+ for (const er of mix.errors) {
6077
+ if (er instanceof Invalid) {
6078
+ hints.push(er.cause?.hint ?? '');
6079
+ }
6080
+ }
6081
+ }
6082
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
6083
+ },
6084
+ });
6085
+ })($ || ($ = {}));
6086
+
6054
6087
  ;
6055
6088
  "use strict";
6056
6089
  var $;