« get me outta code hell

infra: coarsely report relation() ancestry in errors via cause - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/sugar.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-02 09:51:24 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-02 09:51:24 -0300
commitdc24e6200291caaf3aed5ac4aef8096c1ace47c4 (patch)
treeca816ef9d352f6eda746b0365321a5350c8fead4 /src/util/sugar.js
parent6d3b703b1278323ea37690c32185828a91feccba (diff)
infra: coarsely report relation() ancestry in errors via cause
Diffstat (limited to 'src/util/sugar.js')
-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 da21d6d..c11024e 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