-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chain exception re-raise in map_exceptions
#678
Conversation
Preserves the exception chain instead of displaying "During handling of the above exception, another exception occurred" in the traceback
I'd like to get a few concrete before / after examples for this still. |
Makes sense, yup. Thanks 😌
I verified this with the following... before: >>> import httpcore
>>> httpcore.request("GET", "https://blahblahblahnope/")
Traceback (most recent call last):
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_exceptions.py", line 10, in map_exceptions
yield
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/backends/sync.py", line 94, in connect_tcp
sock = socket.create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 826, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 961, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_api.py", line 39, in request
return pool.request(
^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/interfaces.py", line 43, in request
response = self.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection_pool.py", line 253, in handle_request
raise exc
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection_pool.py", line 237, in handle_request
response = connection.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 86, in handle_request
raise exc
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 63, in handle_request
stream = self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 111, in _connect
stream = self._network_backend.connect_tcp(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/backends/sync.py", line 93, in connect_tcp
with map_exceptions(exc_map):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
self.gen.throw(typ, value, traceback)
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc)
httpcore.ConnectError: [Errno 8] nodename nor servname provided, or not known after: >>> import httpcore
>>> httpcore.request("GET", "https://blahblahblahnope/")
Traceback (most recent call last):
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_exceptions.py", line 10, in map_exceptions
yield
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/backends/sync.py", line 94, in connect_tcp
sock = socket.create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 826, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 961, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_api.py", line 39, in request
return pool.request(
^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/interfaces.py", line 43, in request
response = self.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection_pool.py", line 253, in handle_request
raise exc
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection_pool.py", line 237, in handle_request
response = connection.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 86, in handle_request
raise exc
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 63, in handle_request
stream = self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 111, in _connect
stream = self._network_backend.connect_tcp(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/backends/sync.py", line 93, in connect_tcp
with map_exceptions(exc_map):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
self.gen.throw(typ, value, traceback)
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: [Errno 8] nodename nor servname provided, or not known And yes, the change of traceback from "During handling of the above exception, another exception occurred" to "The above exception was the direct cause of the following exception" makes complete sense. I'll leave the merge to you. |
Preserves the exception chain instead of displaying "During handling of the above exception, another exception occurred" in the traceback.
Related to #677