Closed
Description
The behavior below is correct, but the Exception type / error message could be more helpful.
Example problem code and results
Adafruit CircuitPython 7.3.2 on 2022-07-20; Adafruit QT Py ESP32S2 with ESP32S2
>>>
>>> import wifi
>>> import socketpool
>>> from secrets import secrets
>>> wifi.radio.connect(secrets["ssid"], secrets["password"])
>>> pool = socketpool.SocketPool(wifi.radio)
>>> server="nosuchhostname"
>>> pool.getaddrinfo(host=server, port=443)[0][4][0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: -2
>>>
Expected result:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SocketPoolNameError: No such domain name
or at least some text describing what OSError of -2 means, but since DNS failure is a common error, it would be nicer to be able to do, say:
try:
pool.getaddrinfo(host=server, port=443)[0][4][0]
except SocketPoolNameError:
server = false # mark unavailable
rather than special-casing the exception every time you do a DNS lookup:
try:
pool.getaddrinfo(host=server, port=443)[0][4][0]
except OSError as e:
if int(str(e)) == -2:
server = false # mark unavailable
else:
raise e
Thank you for your consideration and all your hard work!