NIFTI-Reader-JS icon indicating copy to clipboard operation
NIFTI-Reader-JS copied to clipboard

Failure to read header results in writing to stderr

Open effigies opened this issue 1 year ago • 2 comments

https://github.com/rii-mango/NIFTI-Reader-JS/blob/0e406b03775d5687911f9440dffa65d7b0886137/src/nifti.ts#L143-L145

It's not ideal to have console.error obligatorily called by a library, as it pollutes my output. I'm going to handle a null return value myself. Would it be possible to either remove the call or make it possible to turn off?

In the short term, I'm just wrapping:

function readHeaderQuiet(buf: ArrayBuffer) {
  const console_error = console.error
  console.error = () => {}
  const header = readHeader(buf)
  console.error = console_error
  return header
}

effigies avatar Aug 12 '24 20:08 effigies

@effigies, would you prefer throw new Error('That file does not appear to be NIFTI!')? I think it is definitely helpful to tell the user something doesn't look correct. I have personally found this useful in Niivue.

hanayik avatar Aug 12 '24 20:08 hanayik

I'm perfectly happy with null, but I can catch an error, too.

effigies avatar Aug 12 '24 21:08 effigies

Closing as the PR from @nellh has been merged into the release version.

neurolabusc avatar Feb 16 '25 12:02 neurolabusc