« get me outta code hell

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:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index da21d6d0..c11024e1 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -594,6 +594,17 @@ export function decorateErrorWithIndex(fn) {
   };
 }
 
+export function decorateErrorWithCause(fn, cause) {
+  return (...args) => {
+    try {
+      return fn(...args);
+    } catch (error) {
+      error.cause = cause;
+      throw error;
+    }
+  };
+}
+
 // Delicious function annotations, such as:
 //
 //   (*bound) soWeAreBackInTheMine