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

Projects
None yet
4 participants
@xrmx
Contributor

xrmx commented May 23, 2018

log.exception should not be used outside exception handlers

oauth/services: don't abuse log.exception
log.exception should not be used outside exception handlers
@humitos

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

xrmx commented May 23, 2018

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

@humitos

This comment has been minimized.

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

This comment has been minimized.

Contributor

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 rtfd:master May 24, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@ericholscher

This comment has been minimized.

Member

ericholscher commented May 24, 2018

Thanks!

@xrmx xrmx deleted the italia:logexception branch May 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment