@@ -16,7 +16,7 @@ import { FileTree } from '../types/filetree.ts'
1616import { ColumnsMap } from '../types/columns.ts'
1717import { readEntities } from './entities.ts'
1818import { DatasetIssues } from '../issues/datasetIssues.ts'
19- import { walkBack } from '../files/inheritance.ts'
19+ import { readSidecars } from '../files/inheritance.ts'
2020import { parseGzip } from '../files/gzip.ts'
2121import { loadTSV , loadTSVGZ } from '../files/tsv.ts'
2222import { parseTIFF } from '../files/tiff.ts'
@@ -194,29 +194,18 @@ export class BIDSContext implements Context {
194194 if ( this . extension === '.json' ) {
195195 return
196196 }
197- let sidecars : BIDSFile [ ] = [ ]
197+ let sidecars : Map < string , Record < string , unknown > >
198198 try {
199- sidecars = [ ...walkBack ( this . file ) ]
200- } catch ( error ) {
201- if (
202- error && typeof error === 'object' && 'code' in error &&
203- error . code === 'MULTIPLE_INHERITABLE_FILES'
204- ) {
205- // @ts -expect-error
199+ sidecars = await readSidecars ( this . file )
200+ } catch ( error : any ) {
201+ if ( error ?. code ) {
206202 this . dataset . issues . add ( error )
203+ return
207204 } else {
208205 throw error
209206 }
210207 }
211- for ( const file of sidecars ) {
212- const json = await loadJSON ( file ) . catch ( ( error ) : Record < string , unknown > => {
213- if ( error . key ) {
214- this . dataset . issues . add ( { code : error . key , location : file . path } )
215- return { }
216- } else {
217- throw error
218- }
219- } )
208+ for ( const [ path , json ] of sidecars . entries ( ) ) {
220209 const overrides = Object . keys ( this . sidecar ) . filter ( ( x ) => Object . hasOwn ( json , x ) )
221210 for ( const key of overrides ) {
222211 if ( json [ key ] !== this . sidecar [ key ] ) {
@@ -225,14 +214,14 @@ export class BIDSContext implements Context {
225214 code : 'SIDECAR_FIELD_OVERRIDE' ,
226215 subCode : key ,
227216 location : overrideLocation ,
228- issueMessage : `Sidecar key defined in ${ file . path } overrides previous value (${
217+ issueMessage : `Sidecar key defined in ${ path } overrides previous value (${
229218 json [ key ]
230219 } ) from ${ overrideLocation } `,
231220 } )
232221 }
233222 }
234223 this . sidecar = { ...json , ...this . sidecar }
235- Object . keys ( json ) . map ( ( x ) => this . sidecarKeyOrigin [ x ] ??= file . path )
224+ Object . keys ( json ) . map ( ( x ) => this . sidecarKeyOrigin [ x ] ??= path )
236225 }
237226 // Hack: round RepetitionTime to 3 decimal places; schema should add rounding function
238227 if ( typeof this . sidecar . RepetitionTime === 'number' ) {
0 commit comments