raise throws the root class Exception or BaseException itself

tx0/python:catch-all-error-thrownstrictwarningsmell

What it finds

raise Exception("not found"): callers can only catch such an error with except Exception, which also catches every unrelated error. A specific builtin such as ValueError, or a class of the project's own, lets them handle this case alone.

From the rule's source, catch_all_error_thrown.rs.

Example from the rule's tests
class Missing(Exception):    pass  def find(key):    if key is None:        raise Exception("no key")tx0 reports: raising Exception itself leaves callers no way to catch only this error    if key == "":        raise BaseExceptiontx0 reports: raising BaseException itself    raise Missing(key)
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:catch-all-error-thrown" = "warning"

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:catch-all-error-thrown] reason="..."

tx0 explain tx0/python:catch-all-error-thrown shows the same in the terminal. Found a false positive? Report it.