Skip to content

Include underlying httpcore exception tracebacks - #1199

Merged
lovelydinosaur merged 1 commit into
masterfrom
include-underlying-traceback
Aug 19, 2020
Merged

Include underlying httpcore exception tracebacks#1199
lovelydinosaur merged 1 commit into
masterfrom
include-underlying-traceback

Conversation

@lovelydinosaur

Copy link
Copy Markdown
Contributor

Closes #1172.

Instead of...

$ venv/bin/python ./example.py Traceback (most recent call last):
File "./example.py", line 2, in <module>
r = httpx.get('https://www.example.org/')
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 170, in get
trust_env=trust_env,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 96, in request
allow_redirects=allow_redirects,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 664, in request
request, auth=auth, allow_redirects=allow_redirects, timeout=timeout,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 694, in send
request, auth=auth, timeout=timeout, allow_redirects=allow_redirects,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 723, in _send_handling_redirects
request, auth=auth, timeout=timeout, history=history
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 759, in _send_handling_auth
response =self._send_single_request(request, timeout)
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 793, in _send_single_request
timeout=timeout.as_dict(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__self.gen.throw(type, value, traceback)
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_exceptions.py", line 359, in map_exceptionsraise mapped_exc(message, **kwargs) fromNone# type:ignorehttpx.ReadError: Server disconnected

We'll instead see...

Traceback (most recent call last):
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_exceptions.py", line 342, in map_exceptionsyield
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 793, in _send_single_request
timeout=timeout.as_dict(),
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection_pool.py", line 189, in request
method, url, headers=headers, stream=stream, timeout=timeout
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/connection.py", line 96, in requestreturnself.connection.request(method, url, headers, stream, timeout)
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/http11.py", line 73, in request
) =self._receive_response(timeout)
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/http11.py", line 130, in _receive_response
event =self._receive_event(timeout)
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_sync/http11.py", line 160, in _receive_event
data =self.socket.read(self.READ_NUM_BYTES, timeout)
File "/Users/tomchristie/GitHub/encode/httpcore/httpcore/_backends/sync.py", line 56, in readraise ReadError("Server disconnected")
httpcore.ReadError: Server disconnected
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./example.py", line 2, in <module>
r = httpx.get('https://www.example.org/')
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 170, in get
trust_env=trust_env,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 96, in request
allow_redirects=allow_redirects,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 664, in request
request, auth=auth, allow_redirects=allow_redirects, timeout=timeout,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 694, in send
request, auth=auth, timeout=timeout, allow_redirects=allow_redirects,
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 723, in _send_handling_redirects
request, auth=auth, timeout=timeout, history=history
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 759, in _send_handling_auth
response =self._send_single_request(request, timeout)
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 793, in _send_single_request
timeout=timeout.as_dict(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__self.gen.throw(type, value, traceback)
File "/Users/tomchristie/GitHub/encode/httpx/httpx/_exceptions.py", line 359, in map_exceptionsraise mapped_exc(message, **kwargs) from exc # type:ignorehttpx.ReadError: Server disconnected

@lovelydinosaurlovelydinosaur added the user-experience Ensuring that users have a good experience using the library label Aug 19, 2020
@j178

j178 commented Aug 19, 2020

Copy link
Copy Markdown
Contributor

Should we port this to httpcore's map_exceptions as well?

@lovelydinosaur

Copy link
Copy Markdown
ContributorAuthor

I think it probably depends. Do we want tracebacks into h11 and h2? Yup, that'd make sense.

Do we want tracebacks into Python's stdlib? Probably not.

@lovelydinosaur
lovelydinosaur merged commit 25507ac into masterAug 19, 2020
@lovelydinosaur
lovelydinosaur deleted the include-underlying-traceback branch August 19, 2020 16:38
@lovelydinosaurlovelydinosaur mentioned this pull request Aug 21, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

user-experienceEnsuring that users have a good experience using the library

Development

Successfully merging this pull request may close these issues.

How about attaching original traceback to exceptions raised in map_exceptions() ?

2 participants

@lovelydinosaur@j178