« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/find.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/find.js b/src/find.js
index 2c97142f..238abda8 100644
--- a/src/find.js
+++ b/src/find.js
@@ -112,7 +112,10 @@ function findHelper({
   // 'quiet' both return null, with 'warn' logging details directly to the
   // console.
   return (fullRef, data, {mode = 'warn'} = {}) => {
+    // TODO: Factor out this validation
+
     if (!fullRef) return null;
+
     if (typeof fullRef !== 'string') {
       throw new TypeError(`Expected a string, got ${typeAppearance(fullRef)}`);
     }
@@ -268,6 +271,18 @@ function findMixedHelper(config) {
     specs = specKeys.map(specKey => findFindSpec(specKey));
 
   return (fullRef, data, {mode = 'warn'} = {}) => {
+    // TODO: Factor out this validation
+
+    if (!fullRef) return null;
+
+    if (typeof fullRef !== 'string') {
+      throw new TypeError(`Expected a string, got ${typeAppearance(fullRef)}`);
+    }
+
+    if (!data) {
+      throw new TypeError(`Expected data to be present`);
+    }
+
     // TODO: Cache stuff below by identity of data
 
     const byName = Object.create(null);