Chain exception re-raise in map_exceptions#678
Merged
Conversation
Preserves the exception chain instead of displaying "During handling of the above exception, another exception occurred" in the traceback
Contributor
Author
|
I'd like to get a few concrete before / after examples for this still. |
lovelydinosaur
approved these changes
May 10, 2023
Contributor
|
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 knownafter: >>> 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 knownAnd 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. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Preserves the exception chain instead of displaying "During handling of the above exception, another exception occurred" in the traceback.
Related to #677