« get me outta code hell

upd8: suppress only "didn't match anything" for sample ref errors - 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-08-11 18:11:26 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-11 18:11:26 -0300
commit1441e7784fda0356dfdea8f2ab360dbb506879f1 (patch)
tree7a8cae9159dc7c2731dfcd86e5708659bdd64592
parented719fabb9bc5a01db8c6ed051c03c388077b05c (diff)
upd8: suppress only "didn't match anything" for sample ref errors
-rw-r--r--src/data/yaml.js40
-rw-r--r--src/util/sugar.js14
2 files changed, 43 insertions, 11 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 37b1f86..3afbe92 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -12,6 +12,7 @@ import T from './things/index.js';
 import {color, ENABLE_COLOR, logInfo, logWarn} from '../util/cli.js';
 
 import {
+  conditionallySuppressError,
   decorateErrorWithIndex,
   empty,
   mapAggregate,
@@ -1272,8 +1273,7 @@ export function filterReferenceErrors(wikiData) {
       contributorContribsByRef: '_contrib',
       coverArtistContribsByRef: '_contrib',
       referencedTracksByRef: 'track',
-      // Skip sampled track ref errors for now
-      // sampledTracksByRef: 'track',
+      sampledTracksByRef: 'track',
       artTagsByRef: 'artTag',
       originalReleaseTrackByRef: 'track',
     }],
@@ -1335,20 +1335,38 @@ export function filterReferenceErrors(wikiData) {
             const findFn = boundFind[findFnKey];
             const value = thing[property];
 
+            const suppress = fn => conditionallySuppressError(error => {
+              if (property === 'sampledTracksByRef') {
+                // Suppress "didn't match anything" errors in particular, just for samples.
+                // In hsmusic-data we have a lot of "stub" sample data which don't have
+                // corresponding tracks yet, so it won't be useful to report such reference
+                // errors until we take the time to address that. But other errors, like
+                // malformed reference strings or miscapitalized existing tracks, should
+                // still be reported, as samples of existing tracks *do* display on the
+                // website!
+                if (error.message.includes(`Didn't match anything`)) {
+                  return true;
+                }
+              }
+
+              return false;
+            }, fn);
+
             if (Array.isArray(value)) {
               thing[property] = filter(
                 value,
-                decorateErrorWithIndex(findFn),
+                decorateErrorWithIndex(suppress(findFn)),
                 {message: `Reference errors in property ${color.green(property)} (${color.green('find.' + findFnKey)})`});
             } else {
-              nest({message: `Reference error in property ${color.green(property)} (${color.green('find.' + findFnKey)})`}, ({call}) => {
-                try {
-                  call(findFn, value);
-                } catch (error) {
-                  thing[property] = null;
-                  throw error;
-                }
-              });
+              nest({message: `Reference error in property ${color.green(property)} (${color.green('find.' + findFnKey)})`},
+                suppress(({call}) => {
+                  try {
+                    call(findFn, value);
+                  } catch (error) {
+                    thing[property] = null;
+                    throw error;
+                  }
+                }));
             }
           }
         });
diff --git a/src/util/sugar.js b/src/util/sugar.js
index c11024e..487c093 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -605,6 +605,20 @@ export function decorateErrorWithCause(fn, cause) {
   };
 }
 
+export function conditionallySuppressError(conditionFn, callbackFn) {
+  return (...args) => {
+    try {
+      return callbackFn(...args);
+    } catch (error) {
+      if (conditionFn(error, ...args) === true) {
+        return;
+      }
+
+      throw error;
+    }
+  };
+}
+
 // Delicious function annotations, such as:
 //
 //   (*bound) soWeAreBackInTheMine