« get me outta code hell

data: improve default Thing util.inspect resiliency - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-19 21:46:10 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-19 21:47:31 -0300
commit9da8aa3ddcca68f3183ac2b1c187ce1b5f98e2d1 (patch)
treef929bd6a1284b8a6e9d77e36d7f13bedb258efff
parentcebd7f4a32350f30c481b54d4777a6c910d5bcc1 (diff)
data: improve default Thing util.inspect resiliency
-rw-r--r--src/data/thing.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/data/thing.js b/src/data/thing.js
index 9a8cec9..29f50d2 100644
--- a/src/data/thing.js
+++ b/src/data/thing.js
@@ -33,17 +33,36 @@ export default class Thing extends CacheableObject {
     },
   };
 
+  static [Symbol.for('Thing.selectAll')] = _wikiData => [];
+
   // Default custom inspect function, which may be overridden by Thing
   // subclasses. This will be used when displaying aggregate errors and other
   // command-line logging - it's the place to provide information useful in
   // identifying the Thing being presented.
   [inspect.custom]() {
-    const cname = this.constructor.name;
+    const constructorName = this.constructor.name;
+
+    let name;
+    try {
+      if (this.name) {
+        name = colors.green(`"${this.name}"`);
+      }
+    } catch (error) {
+      name = colors.yellow(`couldn't get name`);
+    }
+
+    let reference;
+    try {
+      if (this.directory) {
+        reference = colors.blue(Thing.getReference(this));
+      }
+    } catch (error) {
+      reference = colors.yellow(`couldn't get reference`);
+    }
 
     return (
-      (this.name ? `${cname} ${colors.green(`"${this.name}"`)}` : `${cname}`) +
-      (this.directory ? ` (${colors.blue(Thing.getReference(this))})` : '')
-    );
+      (name ? `${constructorName} ${name}` : `${constructorName}`) +
+      (reference ? ` (${reference})` : ''));
   }
 
   static getReference(thing) {