« get me outta code hell

util, test: WIP decorate error with index symbol - 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>2023-09-30 08:29:13 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-30 08:29:13 -0300
commit13b25a8d48d142b60d5c351aad4ad1bf80104320 (patch)
treec77d7c24a962aea5f14cf6da8bc222e8394cab23
parent38e8ed330aa238dc258b7749ce704eb98f5ac670 (diff)
util, test: WIP decorate error with index symbol
-rw-r--r--src/util/sugar.js1
-rw-r--r--test/unit/data/composite/common-utilities/withPropertiesFromObject.js43
2 files changed, 44 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 29fcf84..0522b59 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -624,6 +624,7 @@ export function decorateErrorWithIndex(fn) {
       return fn(x, index, array);
     } catch (error) {
       error.message = `(${colors.yellow(`#${index + 1}`)}) ${error.message}`;
+      error[Symbol.for('hsmusic.sugar.index')] = 1;
       throw error;
     }
   };
diff --git a/test/unit/data/composite/common-utilities/withPropertiesFromObject.js b/test/unit/data/composite/common-utilities/withPropertiesFromObject.js
index 9bcb84c..6b4e10c 100644
--- a/test/unit/data/composite/common-utilities/withPropertiesFromObject.js
+++ b/test/unit/data/composite/common-utilities/withPropertiesFromObject.js
@@ -179,3 +179,46 @@ t.test(`withPropertiesFromObject: output shapes & values`, t => {
       outputDict);
   }
 });
+
+t.test(`withPropertiesFromObject: validate static inputs`, t => {
+  t.plan(3);
+
+  t.throws(
+    () => withPropertiesFromObject({}),
+    {
+      message: `Errors in input options passed to withPropertiesFromObject`,
+      errors: [
+        {message: `Required these inputs: object, properties`},
+      ],
+    });
+
+  t.throws(
+    () => withPropertiesFromObject({
+      object: input.value('intriguing'),
+      properties: input.value('very'),
+      prefix: input.value({yes: 'yup'}),
+    }),
+    {
+      message: `Errors in input options passed to withPropertiesFromObject`,
+      errors: [
+        {message: `object: Expected an object, got string`},
+        {message: 'properties: Expected an array, got string'},
+        {message: 'prefix: Expected a string, got object'},
+      ],
+    });
+
+  t.throws(
+    () => withPropertiesFromObject({
+      object: input.value([['abc', 1], ['def', 2], [123, 3]]),
+      properties: input.value(['abc', 'def', 123]),
+    }),
+    {message: `Errors in input options passed to withPropertiesFromObject`, errors: [
+      {message: 'object: Expected an object, got array'},
+      {message: 'properties: Errors validating array items', errors: [
+        {
+          [Symbol.for('hsmusic.sugar.index')]: 2,
+          message: /Expected a string, got number/,
+        },
+      ]},
+    ]});
+});