-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
needs-decisionAwaiting a decision from a maintainerAwaiting a decision from a maintainerruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
In the following code snippet, a TRY400 violation is raised because I use log.error() and not log.exception() in an exception handler. In this case it's by design as I immediately re-raise the exception, I just want to add some message to the exception and I don't want the stacktrace shown twice.
import logging
log = logging.get_logger(__name__)
# The outer app loop...
try:
# actually some function call which can't handle the error but wants to abort...
try:
raise Exception("bad")
except Exception:
# to get some info into the log to "enrich" it...
# and I don't want to see the exception stacktrace twice
log.error("That might mean ..." ) # noqa: TRY400: use log.exception()
raise
except Exception:
log.exception("Caught unhandled exception in outer context")
In my opinion the pattern "in except block, with a log.something + 'raise' in all cases` should be something TRY400 should ignore/be ok with.
saippuakauppias, cbenz and illagrenan
Metadata
Metadata
Assignees
Labels
needs-decisionAwaiting a decision from a maintainerAwaiting a decision from a maintainerruleImplementing or modifying a lint ruleImplementing or modifying a lint rule