Skip to content

Commit

Permalink
Try using flatMap to deal with timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
happy5214 committed Oct 25, 2024
1 parent 1552829 commit 66d6fc1
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions bids-validator/validators/hed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 66d6fc1

Please sign in to comment.