Skip to main content

SKY-L030 · Logic and resilience

Broad exception with trivial handler

High

The catalog gives no severity for this rule; the detector always reports HIGH.

except Exception: (or BaseException) whose only action is to return a placeholder such as None, {} or []. Every possible error, including bugs in your own code, turns into an ordinary-looking empty result.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The caller cannot tell "no data" from "something broke". In the example below a typo in fetch_flags or an expired API token makes every feature flag read as off, and the service keeps running in the wrong mode with no log line to explain why.

What Skylos flags

config/flags.py · PythonReported on line 7
"""Feature flags from the config service."""  def load_feature_flags(client):    try:        return client.fetch_flags()    except Exception:        return {}

What Skylos leaves alone

config/flags.py · Python
"""Feature flags from the config service."""  def load_feature_flags(client):    try:        return client.fetch_flags()    except (ConnectionError, TimeoutError):        return {}

Why Skylos leaves it alone

The handler names the failures it expects: the config service being unreachable or slow. Anything else, such as a TypeError from a bug, still raises. SKY-L030 only reports Exception and BaseException.

How Skylos decides

  1. Runs with --quality on Python files. Looks at every except clause that names Exception or BaseException, alone or in a tuple. A bare except: is left to SKY-L002 and SKY-L007.
  2. The body must be trivial and contain a return: only pass, continue, ..., bare strings and return of None, "", an empty [], {} or (), or list(), dict(), set() or tuple() with no arguments.
  3. Skips the handler when it logs through a name logger, logging or log, or raises. A trivial handler without a return is SKY-L007's case, not this rule's.
  4. Reports HIGH on the except line.

How to fix it

Catch the failures you expect, and log them so an outage leaves a trace. Let other errors raise.

config/flags.py · Python · the fix, against the flagged file
"""Feature flags from the config service.""" Added: import logging Added: logger = logging.getLogger(__name__)Added:  Added:  def load_feature_flags(client):    try:        return client.fetch_flags()Removed:     except Exception:Added:     except (ConnectionError, TimeoutError):Added:         logger.warning("config service unavailable; all flags off")        return {}

When it can be wrong

  • A deliberate top-level fallback, such as an optional plugin hook that must never break the caller, is reported.
  • It misses a broad handler that returns any other fixed value, such as return False, return 0 or return DEFAULT_FLAGS, which hides errors just as well.

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 except line.

    Python
    except Exception:  # skylos: ignore[SKY-L030] plugin hooks must never fail
  • [tool.skylos] ignore = ["SKY-L030"] turns the rule off for the project.

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