@@ -17,7 +17,7 @@ import { ColumnsMap } from '../types/columns.ts'
1717import { readEntities } from './entities.ts'
1818import { findDatatype } from './datatypes.ts'
1919import { DatasetIssues } from '../issues/datasetIssues.ts'
20- import { walkBack } from '../files/inheritance.ts'
20+ import { readSidecars } from '../files/inheritance.ts'
2121import { parseGzip } from '../files/gzip.ts'
2222import { loadTSV , loadTSVGZ } from '../files/tsv.ts'
2323import { parseTIFF } from '../files/tiff.ts'
@@ -201,29 +201,18 @@ export class BIDSContext implements Context {
201201 if ( this . extension === '.json' ) {
202202 return
203203 }
204- let sidecars : BIDSFile [ ] = [ ]
204+ let sidecars : Map < string , Record < string , unknown > >
205205 try {
206- sidecars = [ ...walkBack ( this . file ) ]
207- } catch ( error ) {
208- if (
209- error && typeof error === 'object' && 'code' in error &&
210- error . code === 'MULTIPLE_INHERITABLE_FILES'
211- ) {
212- // @ts -expect-error
206+ sidecars = await readSidecars ( this . file )
207+ } catch ( error : any ) {
208+ if ( error ?. code ) {
213209 this . dataset . issues . add ( error )
210+ return
214211 } else {
215212 throw error
216213 }
217214 }
218- for ( const file of sidecars ) {
219- const json = await loadJSON ( file ) . catch ( ( error ) : Record < string , unknown > => {
220- if ( error . key ) {
221- this . dataset . issues . add ( { code : error . key , location : file . path } )
222- return { }
223- } else {
224- throw error
225- }
226- } )
215+ for ( const [ path , json ] of sidecars . entries ( ) ) {
227216 const overrides = Object . keys ( this . sidecar ) . filter ( ( x ) => Object . hasOwn ( json , x ) )
228217 for ( const key of overrides ) {
229218 if ( json [ key ] !== this . sidecar [ key ] ) {
@@ -232,14 +221,14 @@ export class BIDSContext implements Context {
232221 code : 'SIDECAR_FIELD_OVERRIDE' ,
233222 subCode : key ,
234223 location : overrideLocation ,
235- issueMessage : `Sidecar key defined in ${ file . path } overrides previous value (${
224+ issueMessage : `Sidecar key defined in ${ path } overrides previous value (${
236225 json [ key ]
237226 } ) from ${ overrideLocation } `,
238227 } )
239228 }
240229 }
241230 this . sidecar = { ...json , ...this . sidecar }
242- Object . keys ( json ) . map ( ( x ) => this . sidecarKeyOrigin [ x ] ??= file . path )
231+ Object . keys ( json ) . map ( ( x ) => this . sidecarKeyOrigin [ x ] ??= path )
243232 }
244233 // Hack: round RepetitionTime to 3 decimal places; schema should add rounding function
245234 if ( typeof this . sidecar . RepetitionTime === 'number' ) {
0 commit comments