« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/yaml.js33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 37f31800..1d35bae8 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -21,6 +21,7 @@ import {
   annotateErrorWithFile,
   conditionallySuppressError,
   decorateErrorWithIndex,
+  decorateErrorWithAnnotation,
   empty,
   filterProperties,
   openAggregate,
@@ -1119,32 +1120,20 @@ export async function loadAndProcessDataDocuments({dataPath}) {
   });
   const wikiDataResult = {};
 
-  const _getFileFromArgument = arg =>
-    (typeof arg === 'object'
-      ? arg.file
-      : arg);
-
   function decorateErrorWithFile(fn) {
-    return (...args) => {
-      try {
-        return fn(...args);
-      } catch (caughtError) {
-        const file = _getFileFromArgument(args[0]);
-        throw annotateErrorWithFile(caughtError, path.relative(dataPath, file));
-      }
-    };
+    return decorateErrorWithAnnotation(fn,
+      (caughtError, firstArg) =>
+        annotateErrorWithFile(
+          caughtError,
+          path.relative(
+            dataPath,
+            (typeof firstArg === 'object'
+              ? firstArg.file
+              : firstArg))));
   }
 
-  // Certified gensync moment.
   function asyncDecorateErrorWithFile(fn) {
-    return async (...args) => {
-      try {
-        return await fn(...args);
-      } catch (caughtError) {
-        const file = _getFileFromArgument(args[0]);
-        throw annotateErrorWithFile(caughtError, path.relative(dataPath, file));
-      }
-    };
+    return decorateErrorWithFile(fn).async;
   }
 
   for (const dataStep of dataSteps) {