HDF-NI / hdf5.node

A node module for reading/writing the HDF5 file format.
MIT License
123 stars 40 forks source link

Can't catch broken hdf5 file #73

Closed NINI1988 closed 5 years ago

NINI1988 commented 6 years ago

It is not possible to catch opening a broken hdf5 file.

try{
  var file = new hdf5.File('broken.h5', Access.ACC_RDONLY);
  file.close();
}catch(error){
  console.error(error);
}

broken.zip

Would it be possible to use the c++ version of hdf5 to catch exceptions?

rimmartin commented 6 years ago

This I believe is a different issue related to where

v8::Isolate::GetCurrent()->ThrowException(
+            v8::Exception::TypeError(String::NewFromUtf8(v8::Isolate::GetCurrent(), ss.str().c_str())));

is valid to do. c++ calls the same H5Fopen we do

I'm working on these

rimmartin commented 6 years ago

I use

throw  std::invalid_argument(ss.str());

to throw it over where Isolate GetCurrent works. the error = true needs to be set first

rimmartin commented 6 years ago

Is it ok if broken.h5 is committed to test/examples?

rimmartin commented 6 years ago

I've committed. Skipped the test until a broke.h5 example is available.

The exception is catching on the javascript side.

The H5Fopen is noisy on the cerr stream.

Adding a File.isHdf5 which calls H5Fis_hdf5

NINI1988 commented 6 years ago

Yes, you can use the h5 file.

rimmartin commented 6 years ago

turned this test on

the cerr piped to terminal by default in h5 is noisy on this one. Thinking about it

NINI1988 commented 6 years ago

We could disable error printing in hdf5.

https://support.hdfgroup.org/HDF5/doc/H5.user/Errors.html

rimmartin commented 6 years ago

I've wanted to rdirect to a nodejs stream; a couple of time a nodejs native side stream was being introduced but didn't make the cut into their releases

Probably make it optional to disable or redirect to a callback function

rimmartin commented 6 years ago

or add a module for https://support.hdfgroup.org/HDF5/doc/RM/RM_H5E.html

rimmartin commented 6 years ago

I think a release of v0.3.4 and then added error handling changes in next version would be good