-
Notifications
You must be signed in to change notification settings - Fork 300
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
Fix exception causes in package.py #662
Conversation
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.
Makes sense to me. That said, can you provide a link to the Python docs or an article/guide that recommends this change?
Also, one nitpick on the variable name before you proceed.
@@ -182,22 +182,22 @@ def run_gpg(cls, gpg_args: Tuple[str, ...]) -> None: | |||
try: | |||
subprocess.check_call(gpg_args) | |||
return | |||
except FileNotFoundError: | |||
except FileNotFoundError as e: |
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.
Thus far, we've used exc
for the exception:
except FileNotFoundError as e: | |
except FileNotFoundError as exc: |
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.
Will do.
Regarding documentation, there's this: https://www.python.org/dev/peps/pep-0344/#enhanced-reporting |
@bhrutledge correct me if I'm wrong but we don't print stack traces as a result of these exceptions. This seems like work with no end-user value. |
Good point; they're captured in Lines 24 to 28 in f922eeb
Except maybe for people who use Twine as a library? Also, this reminds me that we've talked recently in #586 (comment) about adding the traceback to So, since this seems harmless, and if @cool-RR is still motivated to do it, I'm game to review it. One note: looking over other projects where @cool-RR has done this, a common suggestion is to use Also, I appreciate the education in exception handling. |
I think almost all of those people are handling exceptions appropriately. None have reported this as a problem. I'd be wary of saying "This seems harmless because it might help people who ostensibly don't have a problem yet?".
Frankly, if we're not benefiting someone here (ourselves, end-users, or API users) I'm not sure that we should maintain this regardless of whether it's harmless. If we want to spin this for API users, I think we still need to pump the breaks and think about what that looks like without just merging this. What do we want exception handling to look like for an API user? What do we want them to see and have for debugging? Should we always use |
Agreed. I'm going to close this, and we revisit it if necessary. @cool-RR Thanks for proposal, and keeping it minimal. Good luck on your mission. 😉 |
Woops, definitely meant "merge" not "maintain". Thanks for talking through this with me @bhrutledge |
I understand. Thanks for your time and attention. |
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 ofraise from
tells Python to put a more accurate message between the tracebacks. Instead of this:You'll get this:
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!