From 66d6fc16d1cf0a4951e9d985980919f810ebd5af Mon Sep 17 00:00:00 2001 From: Alexander Jones Date: Fri, 25 Oct 2024 14:08:10 -0500 Subject: [PATCH] Try using flatMap to deal with timeouts --- bids-validator/validators/hed.js | 41 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/bids-validator/validators/hed.js b/bids-validator/validators/hed.js index 7f0227cab..f61d21f07 100644 --- a/bids-validator/validators/hed.js +++ b/bids-validator/validators/hed.js @@ -33,39 +33,36 @@ async function checkHedStrings(tsvs, jsonContents, jsonFiles) { return [new Issue({ code: 109, file: datasetDescriptionData.file })] } - const issues = [] - for (const [sidecarName, sidecarContents] of Object.entries(jsonContents)) { - let sidecarFile - try { - sidecarFile = buildSidecar(sidecarName, sidecarContents, jsonFiles) - issues.push(...sidecarFile.validate(hedSchemas)) - } catch (issueError) { - issues.push( - ...hedValidator.bids.BidsHedIssue.fromHedIssues( + const sidecarIssues = Object.entries(jsonContents).flatMap( + ([sidecarName, sidecarContents]) => { + let sidecarFile + try { + sidecarFile = buildSidecar(sidecarName, sidecarContents, jsonFiles) + return sidecarFile.validate(hedSchemas) + } catch (issueError) { + return hedValidator.bids.BidsHedIssue.fromHedIssues( issueError, getSidecarFileObject(sidecarName, jsonFiles), - ), - ) - } - } + ) + } + }, + ) - if (issues.some((issue) => issue.isError())) { - return issues + if (sidecarIssues.some((issue) => issue.isError())) { + return sidecarIssues } - for (const tsv of tsvs) { + const tsvIssues = tsvs.flatMap((tsv) => { let tsvFile try { tsvFile = buildTsv(tsv, jsonContents) - issues.push(...tsvFile.validate(hedSchemas)) + return tsvFile.validate(hedSchemas) } catch (issueError) { - issues.push( - ...hedValidator.bids.BidsHedIssue.fromHedIssues(issueError, tsv.file), - ) + return hedValidator.bids.BidsHedIssue.fromHedIssues(issueError, tsv.file) } - } + }) - return issues + return [...sidecarIssues, ...tsvIssues] } function buildSidecar(sidecarName, sidecarContents, jsonFiles) {