@yuneta/gobj-js 7.26.14 → 7.26.15

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.
@@ -3284,13 +3284,20 @@
3284
3284
  }
3285
3285
  /************************************************************
3286
3286
  * JSON.stringify for a log line: a circular object (a gobj,
3287
- * a DOM node) must not make the log call itself throw.
3287
+ * a DOM node), a BigInt or a toJSON() that throws must not make
3288
+ * the log call itself throw -- and neither must the fallback:
3289
+ * String() throws too, on an object with no prototype or with a
3290
+ * toString() that throws.
3288
3291
  ************************************************************/
3289
3292
  function log_stringify(v) {
3290
3293
  try {
3291
3294
  return JSON.stringify(v);
3292
3295
  } catch (e) {
3293
- return String(v);
3296
+ try {
3297
+ return String(v);
3298
+ } catch (e2) {
3299
+ return `<${typeof v}: not printable>`;
3300
+ }
3294
3301
  }
3295
3302
  }
3296
3303
  function format_log(format) {
@@ -5257,17 +5264,6 @@
5257
5264
  return jdb;
5258
5265
  }
5259
5266
  /********************************************
5260
- * A value as json text for a log line: the error path must not throw
5261
- * (a circular record, a BigInt).
5262
- ********************************************/
5263
- function safe_json_text(v) {
5264
- try {
5265
- return JSON.stringify(v);
5266
- } catch (e) {
5267
- return `<${typeof v}: not json (${e.message})>`;
5268
- }
5269
- }
5270
- /********************************************
5271
5267
  *
5272
5268
  ********************************************/
5273
5269
  function jdb_update(jdb, topic_name, path, kw) {
@@ -5277,7 +5273,7 @@
5277
5273
  return null;
5278
5274
  }
5279
5275
  if (!is_object(kw) || empty_string(kw["id"])) {
5280
- log_error(`jdb_update: record without id: ${safe_json_text(kw)}`);
5276
+ log_error(`jdb_update: record without id: ${log_stringify(kw)}`);
5281
5277
  return null;
5282
5278
  }
5283
5279
  if (!is_string(path)) {
@@ -5330,7 +5326,7 @@
5330
5326
  return null;
5331
5327
  }
5332
5328
  if (!is_object(kw) || empty_string(kw["id"])) {
5333
- log_error(`jdb_delete: record without id: ${safe_json_text(kw)}`);
5329
+ log_error(`jdb_delete: record without id: ${log_stringify(kw)}`);
5334
5330
  return null;
5335
5331
  }
5336
5332
  if (!is_string(path)) {