Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check for expected error types, rethrow unknown #2157

Merged
merged 1 commit into from
Oct 11, 2024
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
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 @@
}
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 @@
) 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 @@
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 @@
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
Loading