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
|