rii-mango / NIFTI-Reader-JS

A JavaScript NIfTI file format reader.
MIT License
136 stars 25 forks source link

Failure to read header results in writing to stderr #41

Open effigies opened 1 month ago

effigies commented 1 month ago

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
}
hanayik commented 1 month ago

@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.

effigies commented 1 month ago

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