tlambert03 / nd2

Full-featured nd2 (Nikon NIS Elements) file reader for python. Outputs to numpy, dask, and xarray. Exhaustive metadata extraction
https://tlambert03.github.io/nd2
BSD 3-Clause "New" or "Revised" License
53 stars 15 forks source link

fix: catch exception on file open and release handle #117

Closed tlambert03 closed 1 year ago

tlambert03 commented 1 year ago

fixes #114

@manthey ... this look good?

tlambert03 commented 1 year ago

hmm.. getting lots of segfaults in tests here, and can reproduce locally too

tlambert03 commented 1 year ago

had to use a different approach in the cpdef function here... @manthey would be great if you could confirm that this still works for you. Thanks again for all of your help

manthey commented 1 year ago

No. This latest commit leaves the file handle open. Specifically, the line comp_type = self._attributes().get('compressionType') doesn't throw an exception (because self._attributes() is an empty dict), so we pass through the exception handler and get to trying to get the attributes from self.attributes which fails. Maybe comp_type = self._attributes()['compressionType'] would be better to raise.

tlambert03 commented 1 year ago

Specifically, the line comp_type = self._attributes().get('compressionType') doesn't throw an exception

oh right of course 🤦‍♂️ sorry!

Maybe comp_type = self._attributes()['compressionType'] would be better to raise.

don't want to assert that compressionType is always there ... but i can check that attributes is at least length 6

i updated again... when you have a moment

manthey commented 1 year ago

Yes, this most recent version works. I get "Unknown error reading attributes in file" and the file handle is properly closed.

tlambert03 commented 1 year ago

Excellent. Thanks again for your time. Much appreciated