@@ -29,32 +29,24 @@ async function checkHedStrings(tsvs, jsonContents, jsonFiles) {
29
29
)
30
30
}
31
31
32
- const issues = [ ]
33
- for ( const [ sidecarName , sidecarContents ] of Object . entries ( jsonContents ) ) {
34
- try {
35
- const sidecarFile = buildSidecar ( sidecarName , sidecarContents , jsonFiles )
36
- issues . push ( ...validateFile ( sidecarFile , hedSchemas ) )
37
- } catch ( e ) {
38
- issues . push ( new Issue ( { code : 109 } ) )
39
- return issues
40
- }
41
- }
32
+ const sidecarIssues = validateFiles (
33
+ buildSidecars ( jsonContents , jsonFiles ) ,
34
+ hedSchemas ,
35
+ )
42
36
43
- if ( issues . some ( ( issue ) => issue . isError ( ) ) ) {
44
- return issues
37
+ if ( sidecarIssues . some ( ( issue ) => issue . isError ( ) || issue . code === 109 ) ) {
38
+ return sidecarIssues
45
39
}
46
40
47
- for ( const tsv of tsvs ) {
48
- try {
49
- const tsvFile = buildTsv ( tsv , jsonContents )
50
- issues . push ( ...validateFile ( tsvFile , hedSchemas ) )
51
- } catch ( e ) {
52
- issues . push ( new Issue ( { code : 109 } ) )
53
- return issues
54
- }
55
- }
41
+ const tsvIssues = validateFiles ( buildTsvs ( tsvs , jsonContents ) , hedSchemas )
56
42
57
- return issues
43
+ return [ ...sidecarIssues , ...tsvIssues ]
44
+ }
45
+
46
+ function * buildSidecars ( jsonContents , jsonFiles ) {
47
+ for ( const [ sidecarName , sidecarContents ] of Object . entries ( jsonContents ) ) {
48
+ yield buildSidecar ( sidecarName , sidecarContents , jsonFiles )
49
+ }
58
50
}
59
51
60
52
function buildSidecar ( sidecarName , sidecarContents , jsonFiles ) {
@@ -63,6 +55,12 @@ function buildSidecar(sidecarName, sidecarContents, jsonFiles) {
63
55
return new hedValidator . bids . BidsSidecar ( sidecarName , sidecarContents , file )
64
56
}
65
57
58
+ function * buildTsvs ( tsvs , jsonContents ) {
59
+ for ( const tsv of tsvs ) {
60
+ yield buildTsv ( tsv , jsonContents )
61
+ }
62
+ }
63
+
66
64
function buildTsv ( tsv , jsonContents ) {
67
65
const potentialSidecars = utils . files . potentialLocations (
68
66
tsv . file . relativePath . replace ( '.tsv' , '.json' ) ,
@@ -81,12 +79,20 @@ function buildTsv(tsv, jsonContents) {
81
79
)
82
80
}
83
81
84
- function validateFile ( file , hedSchemas ) {
85
- const issues = file . validate ( hedSchemas )
86
- if ( issues === null ) {
87
- throw new Error ( )
82
+ function validateFiles ( fileGenerator , hedSchemas ) {
83
+ const issues = [ ]
84
+ for ( const file of fileGenerator ) {
85
+ try {
86
+ const fileIssues = file . validate ( hedSchemas )
87
+ if ( fileIssues === null ) {
88
+ return [ new hedValidator . bids . BidsIssue ( 109 ) ]
89
+ }
90
+ issues . push ( fileIssues )
91
+ } catch ( issueError ) {
92
+ return hedValidator . bids . BidsHedIssue . fromHedIssues ( issueError , file . file )
93
+ }
88
94
}
89
- return issues
95
+ return issues . flat ( )
90
96
}
91
97
92
98
function getSidecarFileObject ( sidecarName , jsonFiles ) {
0 commit comments