An except block logs with error, which drops the traceback that exception would record
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.
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") 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:
[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.