Get POSIX errno from HDF5 errors?


In the h5py Python bindings, it would be nice to raise idiomatic Python exceptions such as FileNotFoundError when a file opened for reading does not exist.

To do this reliably, we would need access to the POSIX errno; Python maps from e.g. ENOENT -> FileNotFoundError. HDF5 captures the errno, but as far as I can see, it only provides it formatted into a string. We don’t really want error handling code to be dependent on fragile regexes to extract a number from the string.

Would it be possible for the HDF5 error handling code to store the POSIX errno as well as its own error codes? E.g. the H5E_error2_t struct could grow a posix_errno member. This would be 0 except when the error comes from a system error for which there is an errno.

Another possible avenue would be if HDF5 had an API to pass in a file descriptor instead of a path. That would let h5py open the file using standard Python functions (raising standard Python errors if needed), and then hand the file descriptor to libhdf5. I can’t see any such API at the moment, but maybe I’m missing something?

HDF5 error number changes in 1.10.3

Hi Thomas,

I entered an enhancement report (HDFFV-10631) for this issue.