question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error number (errno) of OSError is None

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tacaswellcommented, Nov 15, 2018

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 ).

0reactions
miccolicommented, Jun 4, 2019

Opened issue #1226 : I understand that changing established behaviour is tricky, but this is clearly an issue that should be reported.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found