-
Notifications
You must be signed in to change notification settings - Fork 1.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
Use 'from' to explicitly chain exceptions #3306
Comments
Hey @jameslamb I don't see an issue with making this change! If you want to update all 1334 places go for it haha |
Thanks! I just had a thought...this is a perfect thing for Hacktoberfest. What do you think about structuring this issue like I set up microsoft/LightGBM#3390, where Hacktoberfest contributors could come and "claim" this fix for a specific submodule. This is the the type of change that I think is perfect for Hacktoberfest contributors, some of whom are making their first or fifth or 10th open source contribution.
The tradeoff in doing that, though, is that if it goes well it would be a lot of PRs that have to be reviewed, which increases the burden on maintainers. What do you think? |
That sounds great @jameslamb! |
ok thanks! I just updated it. I'll also add a PR that hits one of them so people coming here have an example to go off of. |
ok I just added a sample PR. Thanks for being willing to support this. I know it'll be some extra maintenance work, but the PRs should be quick to review and I think a few people will get their first open source contribution ever from this issue, which is sweet. Also, could you please add labels |
Done! Do you want me to merge that PR that we can link to or are we leaving it open as an active example? |
yeah I think it should be merged (if it passes tests and you agree with it, of course). I just added a link to it in the description so people will always be able to click over and see the diff, even if it's merged. |
Awesome sounds good 👍 |
I'll take the next one on the list! (and more if others don't volunteer after Hacktoberfest)
|
hey can I take |
I can take I also can take several others if there's no other volunteers after Hacktoberfest. |
Thanks for opening this @jameslamb! One pattern I've seen a few places that should be special cased is the following: try:
do_something()
except Exception as exc:
self.logger.warning("An exception occurred: %s", exc)
raise exc I'm not sure if this is flagged by try:
do_something()
except Exception as exc:
self.logger.warning("An exception occurred: %s", exc)
raise # <- no need to specify the exception here |
oh good point! You don't need to worry about "chaining" anything since you're just raising the exact exception that got you into that I tested and can confirm mkdir some_nonsense
touch some_nonsense/__init__.py
"""
some_nonsense/trying_stuff.py
"""
try:
raise RuntimeError("hello")
except RuntimeError as exc:
print("you failed this time but keep trying")
raise I tried running
|
i can take |
@luthrap Go for it! As of yesterday that file was actually moved under |
Hello @jameslamb and team, thanks for sharing this super well documented issue. I want to take up |
Just want to add one info if it helps anyone. If you want to run |
Hi everyone, thanks for merging the earlier PR. I would like to take up the following:
There are not too many cases in these directories, so it seems fine to me to get them fixed in one batch. |
@brainless thanks! But could you please hold off for now? This issue was broken up into small pieces so that multiple people who are just getting started with open source could contribute on it, especially for Hacktoberfest 2020. ^ this is my opinion, but I am not a maintainer here. The maintainers may disagree with me and it's ultimately their decision. |
Hey @jameslamb, I see your point. That makes sense. I can hold off on this and find some other issues for Hacktober 2020 for Prefect, if they are labelled. Thanks. |
@brainless Also, they don't get counted until October 1st. |
I was not aware of the counting, just saw it today as the registrations opened. I am looking for a project to start contributing to and continue doing so long term. Hacktoberfest 2020 was just a nudge to start side-work since many projects label the "easy to start" issues and offer more help to project-newcomers. |
Yeah I'm in favor of holding off and tackling in smaller pieces once October starts next Thursday 👻 |
luthrap|#3306|Fix mysql module for explicit chaining
Hmm what else do we need to do to enable it? I have the |
See that PR I linked. To combat spam, digitalocean is now only counting PRs from repos that have the topic No pressure! I'm sure people would come help on this issue even without Hacktoberfest. |
We needed to add |
Ah I see, misread the comment, good stuff 👍 |
hey this is my first contribution !! please assign me src/prefect/environments/storage |
shalika10|PrefectHQ#3306|Fix environments -storage module for explic…
@jameslamb @joshmeek yayy @jcrist my first PR got merged :) |
Hi guys, could "src/prefect/tasks/postgres" be asigned to me? It would be my first contribution too. |
In this case:
Should I make this change:
Or should I raise a |
You should do a bare |
Hi, I could take up spacy tasks. |
Can I take |
I just submitted a PR for |
@jameslamb should i fix the remaining ones considering hacktoberfest is over haha? |
@Abid1998 yes probably! I'm not a maintainer in this project though, so I can't say whether the maintainers here would prefer to receive one pull request which resolves the remaining cases or whether they'd rather see multiple smaller PRs which might be easier to review. |
@jameslamb will work on 1 for now and raise a PR let's see what the maintainers say after that. |
Raised a PR can someone please review it ? |
Fixed by #4255. Closing. |
Current behavior
I wanted to spend a little time contributing this weekend, so I ran
pylint
over this repo. I see this project has a.pylintrc
but it looks likepylint
isn't run in CI, so some things do show up.I found one class of warning from
pylint
that I think is worth addressing: explicitly re-raising exceptions in try-catches withfrom
.The newest version of
pylint
added a check for this. You can see details in "Explicit Exception Chaining". That PEP describes a way to improve stack traces from try-catched exceptions.without
from
with
from
I think this language of "was the direct cause of the following exception" is clearer, and helps you to understand exactly where things started going wrong.
Proposed behavior
Would you be open to a pull request that changes try-catched exceptions in
prefect
to use this pattern? I wanted to ask first because right now there are 1334 places where that happens so it would touch a lot of code.you can see them all like this:
I think this change would improve
prefect
and help save users some debugging time. Especially users who are not very experienced in Python.Thanks for your time and consideration.
Notes for Hacktoberfest Contributors
This issue has been left open for Hacktoberfest 2020 contributors. If that describes you, welcome!
changes/issue3306.yaml
, add your name to the list of contributorschanges/issue3306.yaml
, create one in your pull request, like in use explicit exception chaining in client #3320sub-modules with this problem
src/prefect/client- @jameslamb (use explicit exception chaining in client #3320)src/prefect/core- @brainless (use explicit exception chaining in core and engine #3383)src/prefect/engine- @brainless (use explicit exception chaining in core and engine #3383)src/prefect/environments/storage- @shalika10src/prefect/tasks/aws- @heyitskevinsrc/prefect/tasks/databricks- @rikturr (explicit exception chaining for databricks hook #3448)src/prefect/tasks/gcp- @ericlundy87 (Corrected use from explicitly #3326)src/prefect/tasks/mysql- @luthrap (luthrap|#3306|Fix mysql module for explicit chaining #3428)src/prefect/tasks/postgres- @brunocasarottisrc/prefect/tasks/spacy- @sp1thassrc/prefect/utilities- @gabrielcalderon (Added FROM to explicitly chain exceptions in src/prefect/utilities #3429)NOTE: This issue is not urgent. It's ok to claim a sub-module now and not contribute until Hacktoberfest begins on October 1st.
The text was updated successfully, but these errors were encountered: