[New-bugs-announce] [issue45594] Feature Request: add EHOSTUNREACH subclass to ConnectionError

Nathan Collins report at bugs.python.org
Sun Oct 24 04:30:10 EDT 2021


New submission from Nathan Collins <nathan.collins at gmail.com>:

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

----------
components: Library (Lib)
messages: 404917
nosy: ntc2
priority: normal
severity: normal
status: open
title: Feature Request: add EHOSTUNREACH subclass to ConnectionError
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45594>
_______________________________________


More information about the New-bugs-announce mailing list