You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The command I've invoked: ruff --isolated --select G,TRY test.py
test.py:7:5: TRY400 Use `logging.exception` instead of `logging.error`
test.py:7:12: G201 Logging `.exception(...)` should be used instead of `.error(..., exc_info=True)`
Found 2 errors.
Hm logger.exception has a different meaning than logger.error — logger.error does not include a traceback unless exc_info is set but logger.exception does. I think these rules cover different cases.
G201: If you're going to log a traceback, use .exception instead of .error — this could be an automatic fix because the meaning is retained
TRY400: If you're going to log an error, always log a traceback — this would only be a suggested fix because it changes behavior
Thank you for the extremely clear issue, appreciated as always. I think these are slightly different, but what we could do is change TRY400 to avoid flagging logger.error calls with exc_info=True, since those will include a traceback anyway as per the intent of the rule. (Then, suggesting the use of logging.exception over exc_info=True would be covered separately by G201.) What do you think, @madkinsz?
test.py
Minimal code snipped that reproduces the bug:
Ruff output
The command I've invoked:
ruff --isolated --select G,TRY test.py
After changing the test.py file to:
I get only:
Maybe the broader TRY400 rule is enough, in favor of G201. Not sure what's the rationale for overlapping/duplicate rules in ruff.
ruff --version
The text was updated successfully, but these errors were encountered: