Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/issues/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export const bidsIssues: IssueDefinitionRecord = {
severity: 'error',
reason: 'A json sidecar file was found without a corresponding data file',
},
SIDECAR_FIELD_OVERRIDE: {
severity: 'warning',
reason: 'Sidecar files should not override values assigned at a higher level.',
},
BLACKLISTED_MODALITY: {
severity: 'error',
reason: 'The modality in this file is blacklisted through validator configuration.',
Expand Down
8 changes: 7 additions & 1 deletion src/schema/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, assertObjectMatch } from '@std/assert'
import { assert, assertEquals, assertObjectMatch } from '@std/assert'
import type { DatasetIssues } from '../issues/datasetIssues.ts'
import { BIDSContext } from './context.ts'
import { dataFile, rootFileTree } from './fixtures.test.ts'
Expand All @@ -21,6 +21,12 @@ Deno.test('test context LoadSidecar', async (t) => {
anatValue: 'anat',
})
})
await t.step('Warnings are emitted for overriding sidecar fields', () => {
assertEquals(
context.dataset.issues.get({ code: 'SIDECAR_FIELD_OVERRIDE' }).length,
2,
)
})
})

Deno.test('test context loadSubjects', async (t) => {
Expand Down
14 changes: 13 additions & 1 deletion src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,26 @@ export class BIDSContext implements Context {
}
}
for (const file of sidecars) {
const json = await loadJSON(file).catch((error) => {
const json = await loadJSON(file).catch((error): Record<string, unknown> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to drop @ts-ignore.

if (error.key) {
this.dataset.issues.add({ code: error.key, location: file.path })
return {}
} else {
throw error
}
})
const overrides = Object.keys(this.sidecar).filter((x) => Object.hasOwn(json, x))
for (const key of overrides) {
if (json[key] !== this.sidecar[key]) {
const overrideLocation = this.sidecarKeyOrigin[key]
this.dataset.issues.add({
code: 'SIDECAR_FIELD_OVERRIDE',
subCode: key,
location: overrideLocation,
issueMessage: `Sidecar key defined in ${file.path} overrides previous value (${json[key]}) from ${overrideLocation}`,
})
}
}
this.sidecar = { ...json, ...this.sidecar }
Object.keys(json).map((x) => this.sidecarKeyOrigin[x] ??= file.path)
}
Expand Down
Loading