From 5bc2df3df8c09bb2508b9e484e4207d0eb35d83d Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Thu, 3 Oct 2024 13:10:10 -0700 Subject: [PATCH] Throw exception for readHeader on non-nifti data --- __tests__/nifti-not-nifti.spec.ts | 2 +- src/nifti.ts | 4 ++-- tests/driver-not-nifti.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/nifti-not-nifti.spec.ts b/__tests__/nifti-not-nifti.spec.ts index 2ca2230..725d0fe 100644 --- a/__tests__/nifti-not-nifti.spec.ts +++ b/__tests__/nifti-not-nifti.spec.ts @@ -17,7 +17,7 @@ describe('NIFTI-Reader-JS', function () { }); it('readHeader() should return null', function () { - assert.equal(null, readHeader(data)); + assert.throws(() => readHeader(data), 'That file does not appear to be NIFTI!'); }); }); }); diff --git a/src/nifti.ts b/src/nifti.ts index 84aaa17..7c42fa2 100644 --- a/src/nifti.ts +++ b/src/nifti.ts @@ -123,7 +123,7 @@ export { NIFTIEXTENSION } from "./nifti-extension"; /** * Reads and returns the header object. * @param {ArrayBuffer} data - * @returns {NIFTI1|NIFTI2|null} + * @returns {NIFTI1|NIFTI2} */ export function readHeader(data: ArrayBuffer, isHdrImgPairOK = false) { var header = null; @@ -141,7 +141,7 @@ export { NIFTIEXTENSION } from "./nifti-extension"; if (header) { header.readHeader(data); } else { - console.error("That file does not appear to be NIFTI!"); + throw new Error('That file does not appear to be NIFTI!'); } return header; diff --git a/tests/driver-not-nifti.js b/tests/driver-not-nifti.js index cf81de4..abfae3d 100644 --- a/tests/driver-not-nifti.js +++ b/tests/driver-not-nifti.js @@ -23,7 +23,7 @@ describe('NIFTI-Reader-JS', function () { }); it('readHeader() should return null', function () { - assert.equal(null, nifti.readHeader(data)); + assert.throws(() => readHeader(data), 'That file does not appear to be NIFTI!'); }); }); });