mol_dump_lib 0.0.972 → 0.0.973

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
@@ -6102,6 +6102,93 @@ var $;
6102
6102
  })($mol_rest_code = $.$mol_rest_code || ($.$mol_rest_code = {}));
6103
6103
  })($ || ($ = {}));
6104
6104
 
6105
+ ;
6106
+ "use strict";
6107
+ var $;
6108
+ (function ($) {
6109
+ function cause_serialize(cause) {
6110
+ return JSON.stringify(cause, null, ' ')
6111
+ .replace(/\(/, '<')
6112
+ .replace(/\)/, ' >');
6113
+ }
6114
+ function frame_normalize(frame) {
6115
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
6116
+ .trim()
6117
+ .replace(/at /gm, ' at ')
6118
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
6119
+ }
6120
+ class $mol_error_mix extends AggregateError {
6121
+ cause;
6122
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
6123
+ constructor(message, cause = {}, ...errors) {
6124
+ super(errors, message, { cause });
6125
+ this.cause = cause;
6126
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
6127
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
6128
+ Object.defineProperty(this, 'stack', {
6129
+ get: () => stack_get() + '\n' + [
6130
+ this.cause ?? 'no cause',
6131
+ ...this.errors.flatMap(e => [
6132
+ String(e.stack),
6133
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
6134
+ ])
6135
+ ].map(frame_normalize).join('\n')
6136
+ });
6137
+ Object.defineProperty(this, 'cause', {
6138
+ get: () => cause
6139
+ });
6140
+ }
6141
+ static [Symbol.toPrimitive]() {
6142
+ return this.toString();
6143
+ }
6144
+ static toString() {
6145
+ return $$.$mol_func_name(this);
6146
+ }
6147
+ static make(...params) {
6148
+ return new this(...params);
6149
+ }
6150
+ }
6151
+ $.$mol_error_mix = $mol_error_mix;
6152
+ })($ || ($ = {}));
6153
+
6154
+ ;
6155
+ "use strict";
6156
+ var $;
6157
+ (function ($) {
6158
+ function pass(data) {
6159
+ return data;
6160
+ }
6161
+ function $mol_error_fence(task, fallback, loading = pass) {
6162
+ try {
6163
+ return task();
6164
+ }
6165
+ catch (error) {
6166
+ let normalized;
6167
+ try {
6168
+ normalized = $mol_promise_like(error) ? loading(error) : fallback(error);
6169
+ }
6170
+ catch (sub_error) {
6171
+ normalized = $mol_promise_like(sub_error) ? sub_error : new $mol_error_mix(sub_error.message, { error }, sub_error);
6172
+ }
6173
+ if (normalized instanceof Error || $mol_promise_like(normalized)) {
6174
+ $mol_fail_hidden(normalized);
6175
+ }
6176
+ return normalized;
6177
+ }
6178
+ }
6179
+ $.$mol_error_fence = $mol_error_fence;
6180
+ })($ || ($ = {}));
6181
+
6182
+ ;
6183
+ "use strict";
6184
+ var $;
6185
+ (function ($) {
6186
+ function $mol_error_enriched(cause, cb) {
6187
+ return $mol_error_fence(cb, e => new $mol_error_mix(e.message, cause, e));
6188
+ }
6189
+ $.$mol_error_enriched = $mol_error_enriched;
6190
+ })($ || ($ = {}));
6191
+
6105
6192
  ;
6106
6193
  "use strict";
6107
6194
  var $;
@@ -6154,13 +6241,13 @@ var $;
6154
6241
  return decoder.decode(buffer);
6155
6242
  }
6156
6243
  json() {
6157
- return $mol_wire_sync(this.native).json();
6244
+ return $mol_error_enriched(this, () => $mol_wire_sync(this.native).json());
6158
6245
  }
6159
6246
  blob() {
6160
- return $mol_wire_sync(this.native).blob();
6247
+ return $mol_error_enriched(this, () => $mol_wire_sync(this.native).blob());
6161
6248
  }
6162
6249
  buffer() {
6163
- return $mol_wire_sync(this.native).arrayBuffer();
6250
+ return $mol_error_enriched(this, () => $mol_wire_sync(this.native).arrayBuffer());
6164
6251
  }
6165
6252
  xml() {
6166
6253
  return $mol_dom_parse(this.text(), 'application/xml');
package/web.test.js CHANGED
@@ -3173,6 +3173,39 @@ var $;
3173
3173
  });
3174
3174
  })($ || ($ = {}));
3175
3175
 
3176
+ ;
3177
+ "use strict";
3178
+ var $;
3179
+ (function ($) {
3180
+ $mol_test({
3181
+ 'auto name'() {
3182
+ class Invalid extends $mol_error_mix {
3183
+ }
3184
+ const mix = new Invalid('foo');
3185
+ $mol_assert_equal(mix.name, 'Invalid_Error');
3186
+ },
3187
+ 'simpe mix'() {
3188
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
3189
+ $mol_assert_equal(mix.message, 'foo');
3190
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
3191
+ },
3192
+ 'provide additional info'() {
3193
+ class Invalid extends $mol_error_mix {
3194
+ }
3195
+ 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' }));
3196
+ const hints = [];
3197
+ if (mix instanceof $mol_error_mix) {
3198
+ for (const er of mix.errors) {
3199
+ if (er instanceof Invalid) {
3200
+ hints.push(er.cause?.hint ?? '');
3201
+ }
3202
+ }
3203
+ }
3204
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
3205
+ },
3206
+ });
3207
+ })($ || ($ = {}));
3208
+
3176
3209
  ;
3177
3210
  "use strict";
3178
3211
  var $;