-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
chore: enable ruff lint rule TRY201 and B904 to improve raise
stack traces
#29166
Conversation
When intercepting and re-raising an error in python, it's almost always better to simply `raise` over raising the exception alias ie: `raise ex`. The main reason is that the stack trace often (always?) gets truncated in the process, losing track of where the error occurred. Similarly, when intercepting and re-raising another exception, it's better to `raise AnotherException() from ex`, so I'm fixing and enforcing this as well. I found this while debugging and dealing with incomplete stack traces, and thought it be a good idea to fix and enforce using ruff's TRY201 and B904
raise
stack traces
Summoning some of our backend / python folks - @betodealmeida @dpgaspar @john-bodley , what do you think? |
I think there might be cases where you legitimately don't want to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
yeah I didn't know that until I was like "where's the rest of my stacktrace!?!?! how did we get here?" |
When intercepting and re-raising an error in python, it's almost always better to simply
raise
over raising the exception alias ie:raise ex
. The main reason is that the stack trace often (always?) gets truncated in the process, losing track of where the error occurred.Similarly, when intercepting and re-raising another exception, it's better to
raise AnotherException() from ex
(usingfrom
), so I'm fixing and enforcing this as well.I found this while debugging and dealing with incomplete stack traces, and thought it be a good idea to fix and enforce using ruff's TRY201 and B904