Improve error handling in safe_open_h5