From ce26d09edcddb5489c1277a1edc081671c2174c5 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 10 Oct 2024 16:35:08 -0400 Subject: [PATCH] fix: Check for expected error types, rethrow unknown --- bids-validator/src/schema/context.ts | 24 ++++++++++++++++++------ bids-validator/src/validators/bids.ts | 8 ++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/bids-validator/src/schema/context.ts b/bids-validator/src/schema/context.ts index 75c37bd7b..9adca5d41 100644 --- a/bids-validator/src/schema/context.ts +++ b/bids-validator/src/schema/context.ts @@ -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) @@ -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 + } }) } @@ -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 + } }) } diff --git a/bids-validator/src/validators/bids.ts b/bids-validator/src/validators/bids.ts index 58f693db2..4f5b8cc20 100644 --- a/bids-validator/src/validators/bids.ts +++ b/bids-validator/src/validators/bids.ts @@ -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 + if (error.key) { + dsContext.issues.add({ code: error.key, location: ddFile.path }) + return {} as Record + } else { + throw error + } }) summary.dataProcessed = dsContext.dataset_description.DatasetType === 'derivative' } else {