From 9da8aa3ddcca68f3183ac2b1c187ce1b5f98e2d1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 19 May 2024 21:46:10 -0300 Subject: data: improve default Thing util.inspect resiliency --- src/data/thing.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/data/thing.js b/src/data/thing.js index 9a8cec91..29f50d23 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) { -- cgit 1.3.0-6-gf8a5