Skip to content

Commit

Permalink
fix: Check for expected error types, rethrow unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Oct 10, 2024
1 parent 09222a7 commit ce26d09
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
}

Check warning on line 200 in bids-validator/src/schema/context.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/schema/context.ts#L195-L200

Added lines #L195 - L200 were not covered by tests
})
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
}

Check warning on line 222 in bids-validator/src/schema/context.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/schema/context.ts#L221-L222

Added lines #L221 - L222 were not covered by tests
})
}

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
}

Check warning on line 260 in bids-validator/src/schema/context.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/schema/context.ts#L259-L260

Added lines #L259 - L260 were not covered by tests
})
}

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
}

Check warning on line 64 in bids-validator/src/validators/bids.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/validators/bids.ts#L63-L64

Added lines #L63 - L64 were not covered by tests
})
summary.dataProcessed = dsContext.dataset_description.DatasetType === 'derivative'
} else {
Expand Down

0 comments on commit ce26d09

Please sign in to comment.