Skip to content

Commit

Permalink
add file read issues, have citation.ts report it when applicable.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwblair committed Aug 30, 2024
1 parent 81a6aca commit 066ec3b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
18 changes: 14 additions & 4 deletions bids-validator/src/issues/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ export const bidsIssues: IssueDefinitionRecord = {
severity: 'error',
reason: 'A json sidecar file was found without a corresponding data file',
},
BLACKLISTED_MODALITY: {
severity: 'error',
reason: 'The modality in this file is blacklisted through validator configuration.',
},
CITATION_CFF_VALIDATION_ERROR: {
severity: 'error',
reason:
"The file does not pass validation using the citation.cff standard's schema." +
'https://github.com/citation-file-format/citation-file-format/blob/main/schema-guide.md'
},
FILE_READ: {
severity: 'error',
reason: 'We were unable to read this file.'
}
}

const hedIssues: IssueDefinitionRecord = {
Expand Down Expand Up @@ -191,10 +205,6 @@ const hedIssues: IssueDefinitionRecord = {
reason:
"You should define 'HEDVersion' for this file. If you don't provide this information, the HED validation will use the latest version available.",
},
BLACKLISTED_MODALITY: {
severity: 'error',
reason: 'The modality in this file is blacklisted through validator configuration.',
},
}

export const hedOldToNewLookup: Record<number, Partial<keyof IssueDefinitionRecord>> = {
Expand Down
2 changes: 1 addition & 1 deletion bids-validator/src/validators/citation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ Deno.test('citation validation', async (t) => {
const file = new BIDSFileDeno('tests/data/citation', 'bad.cff')
tree.files[0].text = () => file.text()
await citationValidate({} as GenericSchema, dsContext)
assert(dsContext.issues.size === 1)
assert(dsContext.issues.get({ code: 'CITATION_CFF_VALIDATION_ERROR' }).length === 1)
})
})
6 changes: 5 additions & 1 deletion bids-validator/src/validators/citation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export async function citationValidate(
try {
citation = parse(await citationFile.text())
} catch (error) {
throw error
dsContext.issues.add({
code: 'FILE_READ',
issueMessage: `Error from attempted read of file:\n${error}`,
location: citationFilename,
})
return
}

Check warning on line 27 in bids-validator/src/validators/citation.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/validators/citation.ts#L21-L27

Added lines #L21 - L27 were not covered by tests
const validate = compile(citationSchema)
Expand Down

0 comments on commit 066ec3b

Please sign in to comment.