From 09c0cbd82e957ddf5711f8ca605c8e6407adbdaa Mon Sep 17 00:00:00 2001 From: Alexander Jones Date: Tue, 11 Feb 2025 19:16:49 -0600 Subject: [PATCH 1/2] Clean up HED module issues --- src/validators/hed.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/validators/hed.ts b/src/validators/hed.ts index 202b6ac0..89131e6f 100644 --- a/src/validators/hed.ts +++ b/src/validators/hed.ts @@ -52,61 +52,63 @@ export async function hedValidate( let file let hedValidationIssues = [] as HedIssue[] + if (context.dataset.hedSchemas === null) { + return + } + try { if (context.extension === '.tsv' && context.columns) { if (!('HED' in context.columns) && !sidecarHasHed(context.sidecar)) { return } hedValidationIssues = await setHedSchemas(context.dataset) - - file = await buildHedTsvFile(context) + file = buildHedTsvFile(context) } else if (context.extension === '.json' && sidecarHasHed(context.json)) { - hedValidationIssues = hedValidationIssues = await setHedSchemas(context.dataset) + hedValidationIssues = await setHedSchemas(context.dataset) file = buildHedSidecarFile(context) } if (file) { - hedValidationIssues.push(...file.validate(context.dataset.hedSchemas)) + const fileIssues = file.validate(context.dataset.hedSchemas) ?? [] as HedIssue[] + hedValidationIssues.push(...fileIssues) } } catch (error) { context.dataset.issues.add({ - code: 'HED_ERROR', + code: 'HED_INTERNAL_ERROR', location: context.path, issueMessage: error as string, }) } - hedValidationIssues.map((hedIssue) => { + for (const hedIssue of hedValidationIssues) { const code = hedIssue.code if (code in hedOldToNewLookup) { - const location = hedIssue.file ? hedIssue.file.path : '' + const location = hedIssue.file?.path ?? '' context.dataset.issues.add({ code: hedOldToNewLookup[code], // @ts-expect-error Hidden property - subCode: hedIssue.hedIssue.hedCode, + subCode: hedIssue.hedIssue?.hedCode, location, issueMessage: hedIssue.evidence, }) } - }) + } } function buildHedTsvFile(context: BIDSContext): hedValidator.bids.BidsTsvFile { - const eventFile = new hedValidator.bids.BidsTsvFile( + return new hedValidator.bids.BidsTsvFile( context.path, context.columns, context.file, [], context.sidecar, ) - return eventFile } function buildHedSidecarFile(context: BIDSContext): hedValidator.bids.BidsSidecar { - const sidecarFile = new hedValidator.bids.BidsSidecar( + return new hedValidator.bids.BidsSidecar( context.path, context.json, context.file, ) - return sidecarFile } From 0d701bc8698e87376f5be8ce71ae9765b2a999a6 Mon Sep 17 00:00:00 2001 From: Alexander Jones Date: Wed, 12 Feb 2025 09:25:35 -0600 Subject: [PATCH 2/2] Fix HED test assertions Since the "internal error" for the null pointer is no longer thrown, there is now only one issue for an invalid schema spec on this test. --- src/tests/local/hed-integration.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/local/hed-integration.test.ts b/src/tests/local/hed-integration.test.ts index 2f1f57d1..3ea35694 100644 --- a/src/tests/local/hed-integration.test.ts +++ b/src/tests/local/hed-integration.test.ts @@ -44,7 +44,7 @@ Deno.test('hed-validator fails with bad schema version', async (t) => { const context = new BIDSContext(eventFile, dsContext) await context.asyncLoads() await hedValidate(schema as unknown as GenericSchema, context) - assertEquals(context.dataset.issues.size, 2) - assertEquals(context.dataset.issues.get({ code: 'HED_ERROR' }).length, 2) + assertEquals(context.dataset.issues.size, 1) + assertEquals(context.dataset.issues.get({ code: 'HED_ERROR' }).length, 1) }) })