Skip to content

Commit

Permalink
Merge pull request #2157 from effigies/fix/missing-error-key
Browse files Browse the repository at this point in the history
fix: Check for expected error types, rethrow unknown
  • Loading branch information
rwblair authored Oct 11, 2024
2 parents 41fbafa + ebd86bf commit 3bd537c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
24 changes: 18 additions & 6 deletions bids-validator/src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ export class BIDSContext implements Context {
}
for (const file of sidecars) {
const json = await loadJSON(file).catch((error) => {
this.dataset.issues.add({ code: error.key, location: file.path })
return {}
if (error.key) {
this.dataset.issues.add({ code: error.key, location: file.path })
return {}
} else {
throw error
}
})
this.sidecar = { ...json, ...this.sidecar }
Object.keys(json).map((x) => this.sidecarKeyOrigin[x] ??= file.path)
Expand All @@ -210,8 +214,12 @@ export class BIDSContext implements Context {
) return

this.nifti_header = await loadHeader(this.file).catch((error) => {
this.dataset.issues.add({ code: error.key, location: this.file.path })
return undefined
if (error.key) {
this.dataset.issues.add({ code: error.key, location: this.file.path })
return undefined
} else {
throw error
}
})
}

Expand Down Expand Up @@ -244,8 +252,12 @@ export class BIDSContext implements Context {
return
}
this.json = await loadJSON(this.file).catch((error) => {
this.dataset.issues.add({ code: error.key, location: this.file.path })
return {}
if (error.key) {
this.dataset.issues.add({ code: error.key, location: this.file.path })
return {}
} else {
throw error
}
})
}

Expand Down
8 changes: 6 additions & 2 deletions bids-validator/src/validators/bids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ export async function validate(
const dsContext = new BIDSContextDataset({ options, schema, tree: fileTree })
if (ddFile) {
dsContext.dataset_description = await loadJSON(ddFile).catch((error) => {
dsContext.issues.add({ code: error.key, location: ddFile.path })
return {} as Record<string, unknown>
if (error.key) {
dsContext.issues.add({ code: error.key, location: ddFile.path })
return {} as Record<string, unknown>
} else {
throw error
}
})
summary.dataProcessed = dsContext.dataset_description.DatasetType === 'derivative'
} else {
Expand Down

0 comments on commit 3bd537c

Please sign in to comment.