Error number (errno) of OSError is None
See original GitHub issueI am wondering if it’s expected that error.errno
in raised exception is None
when a hdf5 file is opened in mode w-
but already exist?
My scenario looks like this:
import h5py;
try:
with h5py.File("file-that-already-exist.hdf5", "w-") as f:
# Do something with the file here
except OSError as error:
print(error.errno)
# --> None
print(str(error))
# --> OSError: Unable to create file (unable to open file: name = 'file-that-already-exist.hdf5', errno = 17, error message = 'File exists', flags = 15, o_flags = a02)
Ideally I would like to be able to do:
expecting_error_no_17 = maybe_yes_maybe_no(my_magic_conditions)
try:
with h5py.File("file-that-already-exist.hdf5", "w-") as f:
# Do something with the file here
except OSError as error:
if error.errno == 17 and expecting_error_no_17:
pass
else:
raise
The above code doesn’t work. I can achieve it by parsing the error message for errno
but I am wondering why error.errno
is None
instead of the error number reported in the error message? Is it expected that error.errno
is None
or is this a bug? If it’s expected is there a preferred way of getting the error number or is that up to the user?
h5py.version.info
:
h5py 2.8.0
HDF5 1.10.3
Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 09:55:02)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
sys.platform darwin
sys.maxsize 9223372036854775807
numpy 1.15.3
I am running macOS 10.12.6.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Raising builtin exception with default message in python
OSError is one of the built-in exceptions. It's defined in the "Built-in Exceptions" section, which adds, "The errno attribute is a numeric ...
Read more >errno — Standard errno system symbols — Python 3.11.1 ...
This module makes available standard errno system symbols. The value of each symbol is the corresponding integer value. The names and descriptions are...
Read more >Handling OSError exception in Python - GeeksforGeeks
Let us see how to handle OSError Exceptions in Python. OSError is a built-in exception in Python and serves as the error class...
Read more >errno(3) - Linux manual page - man7.org
1-2001). ENOENT No such file or directory (POSIX.1-2001). Typically, this error results when a specified pathname does not exist, or one of ...
Read more >No space left on device, errno = 28 - OS Error - Google Groups
Issue 22146 in dart: Error when running 'pub serve': OS Error: No space left on device, errno = 28. 366 views.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I do not think we currently get enough information out of the hdf5 layer to provide this (see https://forum.hdfgroup.org/t/get-posix-errno-from-hdf5-errors/5003 ).
Opened issue #1226 : I understand that changing established behaviour is tricky, but this is clearly an issue that should be reported.