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

oauth/services: don't abuse log.exception #4133

Merged
merged 1 commit into from
May 24, 2018

Conversation

xrmx
Copy link
Contributor

@xrmx xrmx commented May 23, 2018

log.exception should not be used outside exception handlers

log.exception should not be used outside exception handlers
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.

I'm not sure I follow this change, though. When an unhandled exception happen, we want to log it with the whole traceback which is useful for debugging.

Those log.exceptions belongs to the clause try/except/else which are valid.

Why do you think it's better to log.error instead of log.exception here?

@xrmx
Copy link
Contributor Author

xrmx commented May 23, 2018

Because else is not for unhandled exceptions but for code that does not raise any exception:

>>> try:
...   raise ValueError
... except KeyError:
...   pass
... else:
...   print('am not here')
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError

@humitos
Copy link
Member

humitos commented May 23, 2018

Yeah, I got confused. Sorry about that.

So, we probably want to refactor that code since if the else is excecuted when any exception was risen, why we are logging an error? It doesn't make sense to me.

@xrmx
Copy link
Contributor Author

xrmx commented May 23, 2018

Because of if resp.status_code == 201: and the likes in the try block.

@humitos
Copy link
Member

humitos commented May 23, 2018

I understand. I'd say that code needs to be rewritten with an easy to follow and clear flow, then :)

@xrmx
Copy link
Contributor Author

xrmx commented May 23, 2018

If you have time I'd do some audit of try-else usage in RTD, the next PR is fixing another misusage :)

@ericholscher ericholscher merged commit 40ee834 into readthedocs:master May 24, 2018
@ericholscher
Copy link
Member

Thanks!

@xrmx xrmx deleted the logexception branch May 29, 2018 07:47
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.

4 participants