From 682b62b33aa6e5a4c512343d0355d32cb1c67c17 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 6 Nov 2023 16:29:16 -0400 Subject: yaml: consolidate logic in async-adaptive decorateErrorWithFile --- src/data/yaml.js | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/data/yaml.js b/src/data/yaml.js index 37f3180..1d35bae 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) { -- cgit 1.3.0-6-gf8a5