diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-11-06 16:29:16 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-11-06 16:29:16 -0400 |
commit | 682b62b33aa6e5a4c512343d0355d32cb1c67c17 (patch) | |
tree | 52fb17c2a48d40c834de33026fd58ae7764c6481 | |
parent | 8d06ad886607e7acdf636e07719bd4fbae3de767 (diff) |
yaml: consolidate logic in async-adaptive decorateErrorWithFile
-rw-r--r-- | src/data/yaml.js | 33 |
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) { |