SKY-L039 · Logic and resilience
Except clause that only re-raises
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-adviceor select the rule (--select SKY-L039). - Finding type
- advice
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
"""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: raiseWhat Skylos leaves alone
"""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 excWhy 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
- Runs with
--qualityon Python files. Looks at everytrystatement;try/except*is not checked. - Walks the
exceptclauses from the last one backwards while each holds a singleraise, either bare orraise excof the caught name. Araise ... from ...or any other statement ends the walk. - Skips the statement when a comment sits inside those clauses (a documented placeholder), when the project's ruff configuration ignores
TRY203orTRY302for the file, and in golden test fixtures (files a test reads as text). - Reports LOW on the first of the trailing re-raise clauses. When every clause only re-raises, the message says the whole
trycan go (or become a plaintry/finally).
How to fix it
Delete the clause. The exception propagates exactly as before.
"""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: raiseWhen 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.
noqacomments 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
exceptline, 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 nearestruff.toml,.ruff.tomlorpyproject.tomlwith a[tool.ruff]table counts, includingper-file-ignores.