@@ -52,61 +52,63 @@ export async function hedValidate(
5252 let file
5353 let hedValidationIssues = [ ] as HedIssue [ ]
5454
55+ if ( context . dataset . hedSchemas === null ) {
56+ return
57+ }
58+
5559 try {
5660 if ( context . extension === '.tsv' && context . columns ) {
5761 if ( ! ( 'HED' in context . columns ) && ! sidecarHasHed ( context . sidecar ) ) {
5862 return
5963 }
6064 hedValidationIssues = await setHedSchemas ( context . dataset )
61-
62- file = await buildHedTsvFile ( context )
65+ file = buildHedTsvFile ( context )
6366 } else if ( context . extension === '.json' && sidecarHasHed ( context . json ) ) {
64- hedValidationIssues = hedValidationIssues = await setHedSchemas ( context . dataset )
67+ hedValidationIssues = await setHedSchemas ( context . dataset )
6568 file = buildHedSidecarFile ( context )
6669 }
6770
6871 if ( file ) {
69- hedValidationIssues . push ( ...file . validate ( context . dataset . hedSchemas ) )
72+ const fileIssues = file . validate ( context . dataset . hedSchemas ) ?? [ ] as HedIssue [ ]
73+ hedValidationIssues . push ( ...fileIssues )
7074 }
7175 } catch ( error ) {
7276 context . dataset . issues . add ( {
73- code : 'HED_ERROR ' ,
77+ code : 'HED_INTERNAL_ERROR ' ,
7478 location : context . path ,
7579 issueMessage : error as string ,
7680 } )
7781 }
7882
79- hedValidationIssues . map ( ( hedIssue ) => {
83+ for ( const hedIssue of hedValidationIssues ) {
8084 const code = hedIssue . code
8185 if ( code in hedOldToNewLookup ) {
82- const location = hedIssue . file ? hedIssue . file . path : ''
86+ const location = hedIssue . file ?. path ?? ''
8387 context . dataset . issues . add ( {
8488 code : hedOldToNewLookup [ code ] ,
8589 // @ts -expect-error Hidden property
86- subCode : hedIssue . hedIssue . hedCode ,
90+ subCode : hedIssue . hedIssue ? .hedCode ,
8791 location,
8892 issueMessage : hedIssue . evidence ,
8993 } )
9094 }
91- } )
95+ }
9296}
9397
9498function buildHedTsvFile ( context : BIDSContext ) : hedValidator . bids . BidsTsvFile {
95- const eventFile = new hedValidator . bids . BidsTsvFile (
99+ return new hedValidator . bids . BidsTsvFile (
96100 context . path ,
97101 context . columns ,
98102 context . file ,
99103 [ ] ,
100104 context . sidecar ,
101105 )
102- return eventFile
103106}
104107
105108function buildHedSidecarFile ( context : BIDSContext ) : hedValidator . bids . BidsSidecar {
106- const sidecarFile = new hedValidator . bids . BidsSidecar (
109+ return new hedValidator . bids . BidsSidecar (
107110 context . path ,
108111 context . json ,
109112 context . file ,
110113 )
111- return sidecarFile
112114}
0 commit comments