An except block logs with error, which drops the traceback that exception would record

tx0/python:error-log-without-tracebackstrictnotesmell

What it finds

In an except block, logger.exception(...) logs the message with the traceback of the exception being handled; logger.error(...) logs only the message, and the place where things went wrong is lost. Reported are error calls on loggers, as deprecated-logger-warn recognizes them, directly in an except block and without an exc_info argument.

From the rule's source, error_log_without_traceback.rs.

Example from the rule's tests
import logging log = logging.getLogger(__name__) def load(path):    try:        return open(path).read()    except OSError:        log.error("cannot read %s", path)tx0 reports: error in an except block drops the traceback        log.error("cannot read", exc_info=True)        log.exception("cannot read")    log.error("outside")
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:error-log-without-traceback" = "note"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:error-log-without-traceback] reason="..."

tx0 explain tx0/python:error-log-without-traceback shows the same in the terminal. Found a false positive? Report it.