Skip to content

Commit

Permalink
Fix handling of IssueErrors thrown from hed-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
happy5214 committed Oct 25, 2024
1 parent 8f3519b commit d5375c2
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions bids-validator/validators/hed.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@ async function checkHedStrings(tsvs, jsonContents, jsonFiles) {
)
}

if (hedSchemas === null) {
return [new Issue({ code: 109, file: datasetDescriptionData.file })]
}

const issues = []
for (const [sidecarName, sidecarContents] of Object.entries(jsonContents)) {
let sidecarFile
try {
const sidecarFile = buildSidecar(sidecarName, sidecarContents, jsonFiles)
issues.push(...validateFile(sidecarFile, hedSchemas))
} catch (e) {
issues.push(new Issue({ code: 109 }))
return issues
sidecarFile = buildSidecar(sidecarName, sidecarContents, jsonFiles)
issues.push(...sidecarFile.validate(hedSchemas))
} catch (issueError) {
issues.push(
...hedValidator.bids.BidsHedIssue.fromHedIssues(
issueError,
getSidecarFileObject(sidecarName, jsonFiles),
),
)
}
}

Expand All @@ -45,12 +54,14 @@ async function checkHedStrings(tsvs, jsonContents, jsonFiles) {
}

for (const tsv of tsvs) {
let tsvFile
try {
const tsvFile = buildTsv(tsv, jsonContents)
issues.push(...validateFile(tsvFile, hedSchemas))
} catch (e) {
issues.push(new Issue({ code: 109 }))
return issues
tsvFile = buildTsv(tsv, jsonContents)
issues.push(...tsvFile.validate(hedSchemas))
} catch (issueError) {
issues.push(
...hedValidator.bids.BidsHedIssue.fromHedIssues(issueError, tsv.file),
)
}
}

Expand Down Expand Up @@ -81,14 +92,6 @@ function buildTsv(tsv, jsonContents) {
)
}

function validateFile(file, hedSchemas) {
const issues = file.validate(hedSchemas)
if (issues === null) {
throw new Error()
}
return issues
}

function getSidecarFileObject(sidecarName, jsonFiles) {
return jsonFiles.filter((file) => {
return file.relativePath === sidecarName
Expand Down

0 comments on commit d5375c2

Please sign in to comment.