Skip to content
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

Do not re-raise the exception if the one that we are checking #4761

Merged
merged 1 commit into from
Oct 16, 2018

Conversation

humitos
Copy link
Member

@humitos humitos commented Oct 16, 2018

I think that this commit introduced the problem: 0432ee8 (this is the PR: #2765)

The problem is that it's always re-raising the exception, even if the problem is the one that we checking in the if. I think this has generated 4.2k Sentry logs: https://sentry.io/read-the-docs/readthedocs-org/issues/628363742/?query=is:unresolved

@humitos humitos requested a review from a team October 16, 2018 07:50
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha yea, I'm surprised the linter didn't pick that up as effectively doing nothing :/

@@ -222,6 +222,7 @@ def safe_makedirs(directory_name):
try:
os.makedirs(directory_name)
except OSError as e:
if e.errno == errno.EEXIST:
if e.errno == errno.EEXIST: # 17, FileExistsError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rewrite this as raise if not e.errno == errno.EEXIST?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can't. Doesn't look like valid syntax to me.

>>> raise if None is []
  File "<stdin>", line 1
    raise if None is []
           ^
SyntaxError: invalid syntax
>>> 
>>> raise if None is [] else 2
  File "<stdin>", line 1
    raise if None is [] else 2
           ^
SyntaxError: invalid syntax

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. We should at least be able to do:

if not e.errno == errno.EEXIST:
   raise

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, maybe we can write it like

if e.errno != errno.EEXIST:
  raise

is that what you ment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, even better :D

@humitos humitos force-pushed the humitos/safemakedirs/exception branch from 81c7d44 to 812b666 Compare October 16, 2018 08:36
@ericholscher
Copy link
Member

👍

@humitos humitos merged commit 039f527 into master Oct 16, 2018
@humitos humitos deleted the humitos/safemakedirs/exception branch October 16, 2018 08:58
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.

2 participants