Skip to main content

SKY-L039 · Logic and resilience

Except clause that only re-raises

Low

The last except clauses of a try contain nothing but raise. The exception would leave the try anyway, so those clauses do nothing except make the reader look for handling that is not there.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans). Only when listed. This is advice outside the default set: the report keeps it in JSON but does not list it, and the gate does not count it, unless you pass --all-advice or select the rule (--select SKY-L039).
Finding type
advice
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Readers assume an except Exception: handles something, and reviewers stop looking for missing error handling. The empty clause is noise that often marks code generated from a template and never finished.

What Skylos flags

payments/charge.py · PythonReported on line 10
"""Charge an order through the payment gateway."""  def charge(gateway, order):    try:        return gateway.charge(order.total)    except gateway.CardDeclined as exc:        order.mark_declined(exc.reason)        return None    except Exception:        raise

What Skylos leaves alone

payments/charge.py · Python
"""Charge an order through the payment gateway.""" from payments.errors import PaymentError  def charge(gateway, order):    try:        return gateway.charge(order.total)    except gateway.CardDeclined:        raise    except Exception as exc:        raise PaymentError(f"charge failed for order {order.id}") from exc

Why Skylos leaves it alone

The re-raise-only clause comes first, and it has a job: it keeps CardDeclined away from the broader except Exception below, which would otherwise wrap it in PaymentError. Skylos only reports re-raise clauses at the end of the list.

How Skylos decides

  1. Runs with --quality on Python files. Looks at every try statement; try/except* is not checked.
  2. Walks the except clauses from the last one backwards while each holds a single raise, either bare or raise exc of the caught name. A raise ... from ... or any other statement ends the walk.
  3. Skips the statement when a comment sits inside those clauses (a documented placeholder), when the project's ruff configuration ignores TRY203 or TRY302 for the file, and in golden test fixtures (files a test reads as text).
  4. Reports LOW on the first of the trailing re-raise clauses. When every clause only re-raises, the message says the whole try can go (or become a plain try/finally).

How to fix it

Delete the clause. The exception propagates exactly as before.

payments/charge.py · Python · the fix, against the flagged file
"""Charge an order through the payment gateway."""  def charge(gateway, order):    try:        return gateway.charge(order.total)    except gateway.CardDeclined as exc:        order.mark_declined(exc.reason)        return NoneRemoved:     except Exception:Removed:         raise

When it can be wrong

  • A clause kept as a reminder of where handling will go is reported unless a comment inside the clause says so.
  • noqa comments that name ruff's code (# noqa: TRY203) do not silence it; only the project's ruff ignore list is read.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put the marker on the reported except line, or write a comment inside the clause to mark it as a deliberate placeholder.

    Python
    except Exception:  # skylos: ignore[SKY-L039] handling added in #412
  • [tool.skylos] ignore = ["SKY-L039"] turns the rule off for the project.

  • A project whose ruff configuration ignores TRY203 (ruff's check for the same pattern) has already declined this rewrite, so Skylos stays quiet there too. The nearest ruff.toml, .ruff.toml or pyproject.toml with a [tool.ruff] table counts, including per-file-ignores.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.