Skip to content

Conversation

cool-RR
Copy link
Contributor

@cool-RR cool-RR commented Jun 12, 2020

I recently went over Matplotlib, Pandas and NumPy, fixing a small mistake in the way that Python 3's exception chaining is used. If you're interested, I can do it here too. I've done it on just one file right now.

The mistake is this: In some parts of the code, an exception is being caught and replaced with a more user-friendly error. In these cases the syntax raise new_error from old_error needs to be used.

Python 3's exception chaining means it shows not only the traceback of the current exception, but that of the original exception (and possibly more.) This is regardless of raise from. The usage of raise from tells Python to put a more accurate message between the tracebacks. Instead of this:

During handling of the above exception, another exception occurred:

You'll get this:

The above exception was the direct cause of the following exception:

The first is inaccurate, because it signifies a bug in the exception-handling code itself, which is a separate situation than wrapping an exception.

Let me know what you think!

@cool-RR cool-RR requested a review from asvetlov as a code owner June 12, 2020 10:09
@codecov-commenter
Copy link

codecov-commenter commented Jun 12, 2020

Codecov Report

Merging #4815 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4815   +/-   ##
=======================================
  Coverage   97.60%   97.60%           
=======================================
  Files          43       43           
  Lines        8932     8932           
  Branches     1406     1406           
=======================================
  Hits         8718     8718           
  Misses         95       95           
  Partials      119      119           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 385b03e...d93150c. Read the comment docs.

@cool-RR
Copy link
Contributor Author

cool-RR commented Jun 12, 2020

If I understand correctly, the test failure here is not related to my change. (I see it's happening on other PRs.)

@codecov-io
Copy link

codecov-io commented Oct 18, 2020

Codecov Report

Merging #4815 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4815      +/-   ##
==========================================
- Coverage   97.66%   97.65%   -0.02%     
==========================================
  Files          43       43              
  Lines        8983     8983              
  Branches     1412     1412              
==========================================
- Hits         8773     8772       -1     
- Misses         97       98       +1     
  Partials      113      113              
Flag Coverage Δ
#unit 97.65% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiohttp/web_fileresponse.py 97.84% <0.00%> (-0.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 78949fd...bb8072e. Read the comment docs.

@asvetlov
Copy link
Member

Agree, you are right.
The proposal makes value and produces better understandable exception info.
I'll merge this PR; please feel free to apply such improvements to all codebase.

@asvetlov asvetlov merged commit d9f0f4d into aio-libs:master Oct 18, 2020
aio-libs-github-bot bot pushed a commit that referenced this pull request Oct 18, 2020
@aio-libs-github-bot
Copy link
Contributor

💚 Backport successful

The PR was backported to the following branches:

aio-libs-github-bot bot added a commit that referenced this pull request Oct 18, 2020
Backports the following commits to 3.7:
 - Fix exception causes in client.py (#4815)

Co-authored-by: Ram Rachum <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants