« 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
path: root/src/util
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 /src/util
parented719fabb9bc5a01db8c6ed051c03c388077b05c (diff)
upd8: suppress only "didn't match anything" for sample ref errors
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index c11024e1..487c093c 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