SKY-L030 · Logic and resilience
Broad exception with trivial handler
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
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
"""Feature flags from the config service.""" def load_feature_flags(client): try: return client.fetch_flags() except Exception: return {}What Skylos leaves alone
"""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
- Runs with
--qualityon Python files. Looks at everyexceptclause that namesExceptionorBaseException, alone or in a tuple. A bareexcept:is left to SKY-L002 and SKY-L007. - The body must be trivial and contain a
return: onlypass,continue,..., bare strings andreturnofNone,"", an empty[],{}or(), orlist(),dict(),set()ortuple()with no arguments. - Skips the handler when it logs through a name
logger,loggingorlog, or raises. A trivial handler without areturnis SKY-L007's case, not this rule's. - Reports HIGH on the
exceptline.
How to fix it
Catch the failures you expect, and log them so an outage leaves a trace. Let other errors raise.
"""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 0orreturn 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
exceptline.Python except Exception: # skylos: ignore[SKY-L030] plugin hooks must never fail[tool.skylos] ignore = ["SKY-L030"]turns the rule off for the project.