This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Feature Request: add EHOSTUNREACH subclass to ConnectionError
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ntc2
Priority: normal Keywords:

Created on 2021-10-24 08:30 by ntc2, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg404917 - (view) Author: Nathan Collins (ntc2) * Date: 2021-10-24 08:30
WHAT

It would be nice if there was a special-case subclass of the standard library OSError/ConnectionError class for C EHOSTUNREACH (a.k.a. "no route to host") errors. Currently there are special-case subclasses of ConnectionError for several other types of connection errors, namely BrokenPipeError, ConnectionAbortedError, ConnectionRefusedError and ConnectionResetError. I'm asking that a new, similar subclass called HostUnreachableError be added, corresponding to C errno EHOSTUNREACH.

HOW

I believe this is as simple as adding four lines to CPython's exceptions.c, e.g. following ECONNABORTED's special treatment via the ConnectionAbortedError subclass there.

WHY

These special case OSError/ConnectionError exceptions are useful for several reasons. First, they give human friendly names to an otherwise less helpful OSError exceptions. Second, they make it easier to write portable code, because different OSes use different C errno numbers for the corresponding C error. For example, EHOSTUNREACH is errno 113 on Linux [1] and 110 on Windows [2].

[1] https://github.com/torvalds/linux/blob/9c0c4d24ac000e52d55348961d3a3ba42065e0cf/include/uapi/asm-generic/errno.h#L96
[2] https://docs.microsoft.com/en-us/cpp/c-runtime-library/errno-constants?view=msvc-160
msg404919 - (view) Author: Nathan Collins (ntc2) * Date: 2021-10-24 08:53
Apparently the existing ConnectionError and its subclasses were added as part of PEP 3151, tracked here: https://bugs.python.org/issue12555 .
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89757
2021-10-24 08:53:25ntc2setmessages: + msg404919
2021-10-24 08:30:10ntc2create