« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/things/composite.js30
-rw-r--r--src/data/things/validators.js6
-rw-r--r--src/util/html.js4
-rw-r--r--src/util/replacer.js4
-rw-r--r--src/util/sugar.js6
5 files changed, 25 insertions, 25 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index 33f49e9b..b6009525 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -395,7 +395,7 @@ function isInputToken(token) {
 
 function getInputTokenShape(token) {
   if (!isInputToken(token)) {
-    throw new TypeError(`Expected an input token, got ${token}`);
+    throw new TypeError(`Expected an input token, got ${typeAppearance(token)}`);
   }
 
   if (typeof token === 'object') {
@@ -407,7 +407,7 @@ function getInputTokenShape(token) {
 
 function getInputTokenValue(token) {
   if (!isInputToken(token)) {
-    throw new TypeError(`Expected an input token, got ${token}`);
+    throw new TypeError(`Expected an input token, got ${typeAppearance(token)}`);
   }
 
   if (typeof token === 'object') {
@@ -464,8 +464,8 @@ function validateInputValue(value, description) {
     } else {
       throw new TypeError(
         (type
-          ? `Expected ${type}, got ${value}`
-          : `Expected value, got ${value}`));
+          ? `Expected ${type}, got ${typeAppearance(value)}`
+          : `Expected value, got ${typeAppearance(value)}`));
     }
   }
 
@@ -478,7 +478,7 @@ function validateInputValue(value, description) {
         : typeof value);
 
     if (typeofValue !== type) {
-      throw new TypeError(`Expected ${type}, got ${typeofValue}`);
+      throw new TypeError(`Expected ${type}, got ${typeAppearance(value)}`);
     }
   }
 
@@ -503,11 +503,11 @@ export function templateCompositeFrom(description) {
 
     validateInputs:
     if ('inputs' in description) {
-      if (Array.isArray(description.inputs)) {
-        push(new Error(`Expected inputs to be object, got array`));
-        break validateInputs;
-      } else if (typeof description.inputs !== 'object') {
-        push(new Error(`Expected inputs to be object, got ${typeof description.inputs}`));
+      if (
+        Array.isArray(description.inputs) ||
+        typeof description.inputs !== 'object'
+      ) {
+        push(new Error(`Expected inputs to be object, got ${typeAppearance(description.inputs)}`));
         break validateInputs;
       }
 
@@ -543,7 +543,7 @@ export function templateCompositeFrom(description) {
         !Array.isArray(description.outputs) &&
         typeof description.outputs !== 'function'
       ) {
-        push(new Error(`Expected outputs to be array or function, got ${typeof description.outputs}`));
+        push(new Error(`Expected outputs to be array or function, got ${typeAppearance(description.outputs)}`));
         break validateOutputs;
       }
 
@@ -552,7 +552,7 @@ export function templateCompositeFrom(description) {
           description.outputs,
           decorateErrorWithIndex(value => {
             if (typeof value !== 'string') {
-              throw new Error(`${value}: Expected string, got ${typeof value}`)
+              throw new Error(`${value}: Expected string, got ${typeAppearance(value)}`)
             } else if (!value.startsWith('#')) {
               throw new Error(`${value}: Expected "#" at start`);
             }
@@ -733,8 +733,8 @@ export function templateCompositeFrom(description) {
           }
 
           for (const name of wrongTypeOutputNames) {
-            const type = typeof providedOptions[name];
-            push(new Error(`${name}: Expected string, got ${type}`));
+            const appearance = typeAppearance(providedOptions[name]);
+            push(new Error(`${name}: Expected string, got ${appearance}`));
           }
         });
 
@@ -865,7 +865,7 @@ export function compositeFrom(description) {
 
   if (!Array.isArray(description.steps)) {
     throw new TypeError(
-      `Expected steps to be array, got ${typeof description.steps}` +
+      `Expected steps to be array, got ${typeAppearance(description.steps)}` +
       (annotation ? ` (${annotation})` : ''));
   }
 
diff --git a/src/data/things/validators.js b/src/data/things/validators.js
index 048f7ebb..ba62fb84 100644
--- a/src/data/things/validators.js
+++ b/src/data/things/validators.js
@@ -1,7 +1,7 @@
 import {inspect as nodeInspect} from 'node:util';
 
 import {colors, ENABLE_COLOR} from '#cli';
-import {empty, withAggregate} from '#sugar';
+import {empty, typeAppearance, withAggregate} from '#sugar';
 
 function inspect(value) {
   return nodeInspect(value, {colors: ENABLE_COLOR});
@@ -15,7 +15,7 @@ export function a(noun) {
 
 export function isType(value, type) {
   if (typeof value !== type)
-    throw new TypeError(`Expected ${a(type)}, got ${typeof value}`);
+    throw new TypeError(`Expected ${a(type)}, got ${typeAppearance(value)}`);
 
   return true;
 }
@@ -132,7 +132,7 @@ export function isObject(value) {
 
 export function isArray(value) {
   if (typeof value !== 'object' || value === null || !Array.isArray(value))
-    throw new TypeError(`Expected an array, got ${value}`);
+    throw new TypeError(`Expected an array, got ${typeAppearance(value)}`);
 
   return true;
 }
diff --git a/src/util/html.js b/src/util/html.js
index c7395fbf..282a52da 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -2,7 +2,7 @@
 
 import {inspect} from 'node:util';
 
-import {empty} from '#sugar';
+import {empty, typeAppearance} from '#sugar';
 import * as commonValidators from '#validators';
 
 // COMPREHENSIVE!
@@ -633,7 +633,7 @@ export class Template {
 
   static validateDescription(description) {
     if (typeof description !== 'object') {
-      throw new TypeError(`Expected object, got ${typeof description}`);
+      throw new TypeError(`Expected object, got ${typeAppearance(description)}`);
     }
 
     if (description === null) {
diff --git a/src/util/replacer.js b/src/util/replacer.js
index 647d1f0e..095ee060 100644
--- a/src/util/replacer.js
+++ b/src/util/replacer.js
@@ -6,7 +6,7 @@
 // for embedding in a wiki webpage.
 
 import * as html from '#html';
-import {escapeRegex} from '#sugar';
+import {escapeRegex, typeAppearance} from '#sugar';
 
 // Syntax literals.
 const tagBeginning = '[[';
@@ -407,7 +407,7 @@ export function postprocessHeadings(inputNodes) {
 
 export function parseInput(input) {
   if (typeof input !== 'string') {
-    throw new TypeError(`Expected input to be string, got ${input}`);
+    throw new TypeError(`Expected input to be string, got ${typeAppearance(input)}`);
   }
 
   try {
diff --git a/src/util/sugar.js b/src/util/sugar.js
index ef6ab18c..29fcf848 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -82,7 +82,7 @@ export function stitchArrays(keyToArray) {
   for (const [key, value] of Object.entries(keyToArray)) {
     if (value === null) continue;
     if (Array.isArray(value)) continue;
-    errors.push(new TypeError(`(${key}) Expected array or null, got ${value}`));
+    errors.push(new TypeError(`(${key}) Expected array or null, got ${typeAppearance(value)}`));
   }
 
   if (!empty(errors)) {
@@ -170,11 +170,11 @@ export function setIntersection(set1, set2) {
 
 export function filterProperties(object, properties) {
   if (typeof object !== 'object' || object === null) {
-    throw new TypeError(`Expected object to be an object, got ${object}`);
+    throw new TypeError(`Expected object to be an object, got ${typeAppearance(object)}`);
   }
 
   if (!Array.isArray(properties)) {
-    throw new TypeError(`Expected properties to be an array, got ${properties}`);
+    throw new TypeError(`Expected properties to be an array, got ${typeAppearance(properties)}`);
   }
 
   const filteredObject = {};