All naked excepts which raise an exception should include previous exception stack
I propose that there should be a strict policy for any new code being committed and all old code as it is found to be offending that any where there is a naked except, that is an except block that catches all exceptions, and an exception is raised within this block, that the previous exceptions exception call stack be preserved in the new raised exception.
For example, in contrib/admin/views/main.py on line 319 there is a naked except and the caught exception object is wrapped by another exception class and then re-raised. This loses the call stack of the originating exception, thus making it potentially very difficult to debug the original exception.
This issue should fix the above and start a policy discussion.
Change History
(9)
Component: |
Uncategorized → Core (Other)
|
Summary: |
NEW POLICY: All naked excepts which raise an exception should include previous exception stack. → All naked excepts which raise an exception should include previous exception stack
|
Triage Stage: |
Unreviewed → Accepted
|
Type: |
Bug → Cleanup/optimization
|
Owner: |
changed from nobody to Jake Rothenbuhler
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
I forgot to add. For those who don't know, there is a rarely used form of the "raise" statement as follows:
This form will use the provided traceback, as opposed to a traceback starting from the current frame. This is how I propose we preserve the originating exception's call stack. It would look something like the following: