Skip to content
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

0.13: some httpcore exceptions are missing from top level package #1023

Closed
2 tasks done
iwoloschin opened this issue Jun 15, 2020 · 4 comments · Fixed by #1044
Closed
2 tasks done

0.13: some httpcore exceptions are missing from top level package #1023

iwoloschin opened this issue Jun 15, 2020 · 4 comments · Fixed by #1044
Labels
bug Something isn't working

Comments

@iwoloschin
Copy link

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

I believe that HTTPError is expected to be the base exception for all exceptions that httpx may raise? Since 0.13 this is no longer true and comments in _exceptions.py indicate this is a bug. In real world use I have at least one bit of code that has failed due to this. I could see an argument for trying to catch a more specific error, but I think this case HTTPError was really nice to use.

Even if users should be using more specific exceptions having a single base exception is an incredibly useful feature for any library and it'd be great if we could ensure this behavior is set for the upcoming 1.0 release.

To reproduce

The following code assumes localhost does not have any webserver running on port 80. Running on httpx 0.12 it correctly catches the HTTPError, running on 0.13 it does not catch the exception (httpcore.ConnectError, which doesn't appear to be properly exported in [\_\_init\_\_.py](https://github.com/encode/httpx/blob/master/httpx/__init__.py), though it is aliased in _exceptions.py`).

import httpx
try:
    httpx.get('http://localhost')
except httpx.HTTPError:
    print('There was an httpx error')

Expected behavior

If HTTPError is the base exception for httpx I'd expect catching HTTPError to actually catch all errors httpx may raise.

Actual behavior

Instead of catching HTTPError it appears that httpcore errors bubble up. This breaks exception handling that expects HTTPError to be the base exception.

Environment

  • OS: macOS 10.15.5
  • Python version: 3.8.3
  • HTTPX version: 0.13
  • Async environment: asyncio
  • HTTP proxy: No
  • Custom certificates: No
@florimondmanca florimondmanca added the bug Something isn't working label Jun 15, 2020
@florimondmanca
Copy link
Member

florimondmanca commented Jun 15, 2020

@iwoloschin I'm tempted to keep the base class issue to #949. But you raised an interesting point about ConnectError not being exposed in __init__.py, which I believe is a bug in itself:

httpcore.ConnectError, which doesn't appear to be properly exported in __init__.py, though it is aliased in _exceptions.py.

So, marking this as bug up for grabs. I'll retitle this issue to reduce its scope and keep any discussions on base classes scoped to #949.

@florimondmanca florimondmanca changed the title HTTPError not base exception for httpx Some httpore exceptions are missing from top level package Jun 15, 2020
@florimondmanca florimondmanca changed the title Some httpore exceptions are missing from top level package 0.13: some httpcore exceptions are missing from top level package Jun 15, 2020
@iwoloschin
Copy link
Author

I made this as a separate issue because I couldn't really find any big, obvious notes that exception handling had changed for 0.13. I didn't even really understand the scope of the change after commenting in #949, after I did some digging and understood what had happened I felt it was worthwhile specifically breaking this out since it might be as simple as a bug against 0.13[.3], with the higher level discussion for #949? I'm fine either way.

I realize that as this is basically all pre-release software there is always a risk of breaking changes, but this project has actually been pretty good about noting breaking changes. Honestly, httpx is such a joy to use that it would be worth dealing with breaking changes anyways, I just was hoping for more notice than "pushed a new release and...oh...it all broke" 😄 .

@florimondmanca
Copy link
Member

Yeah, to be honest we hadn't realized the exception handling API would change so much due to the deferring of the networking layer to httpcore, but here we are. :-) Now we just need some folks to fix things.

@iwoloschin
Copy link
Author

If only we were paid for fixing all of the "small" changes we make 😄 .

Is most of the discussion happening in the gitter room? I can see if I can drop in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants