Closed brondsem closed 1 year ago
Why is getattr(exc_value, "__notes__", None)
triggering a KeyError
? What is HTTPError doing to cause that?
https://github.com/python/cpython/issues/98778 discuss that issue. I just re-read that, and realized I can fix this by creating the HTTPError differently (more correctly, I suppose)
-raise HTTPError('url', 408, 'timeout', None, None)
+raise HTTPError('url', 408, 'timeout', None, io.BytesIO())
So feel free to close this, unless you really want to do extra work :)
This is where it crashes: https://github.com/python/cpython/blob/c3c3871415c86088d45abcf73ccd2c2b09dc5772/Lib/tempfile.py#L477
The problem seems to be that HTTPError
does not call the superclass initializer, but the __getattr__()
method in the superclass requires the file
attribute to be present. When it's not, it crashes with a KeyError
.
Closing since this is a Python stdlib issue.
HTTPError has some weird behavior which causes exceptiongroup to error out when rendering the traceback. There is a cpython issue at https://github.com/python/cpython/issues/98778 about HTTPError's weirdness. But it'd be great if exceptiongroup could help handle this better, so error handling works as expected, and not waiting for a cpython fix and releases.
I found this while using pytest, which uses exceptiongroup.
The setup:
The error: