SKY-L005 · Logic and resilience
Unused exception variable
except SomeError as exc: binds the exception to a name. When the handler never reads that name, the binding does nothing.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans). This is advice that the default report does not list ("measurement"), and unlisted advice is not counted.
--all-advice, or naming the rule in[tool.skylos] selector[tool.skylos.gate] rules, lists and counts it. - Finding type
- advice
Why it matters
It is usually a sign that something was meant to happen with the error and did not: it was not logged, not chained with from exc, not shown to anyone. On its own the extra name is harmless.
What Skylos flags
import json def read_config(path): try: with open(path, encoding="utf-8") as handle: return json.load(handle) except FileNotFoundError as exc: return {}What Skylos leaves alone
import json class ConfigError(Exception): pass def read_config(path): try: with open(path, encoding="utf-8") as handle: return json.load(handle) except json.JSONDecodeError as exc: raise ConfigError(f"{path} is not valid JSON") from excWhy Skylos leaves it alone
from exc reads the name, and chains the original error to the new one so its traceback is kept.
How Skylos decides
- Runs with
--qualityon Python files. Visits everyexceptclause that binds a name withas; the name_is skipped. - Looks for any read of the name inside the handler, nested functions and lambdas included, or an augmented assignment such as
exc += .... - Also accepts a lookup by name through the namespace builtins:
locals()["exc"],vars().get("exc")or"{exc}".format_map(locals()). That proof is dropped when the module rebindslocalsorvars, uses a star import, or callsexec,evalorglobals. - Reports LOW on the
exceptline when no read is found. The rule is advice: the finding is in JSON output, but the terminal list shows it only with--all-advice.
How to fix it
Drop as exc when the error is deliberately ignored, or use the name: log it, or chain it with raise ... from exc.
import json def read_config(path): try: with open(path, encoding="utf-8") as handle: return json.load(handle)Removed: except FileNotFoundError as exc:Added: except FileNotFoundError: return {}When it can be wrong
- A name kept so a debugger can inspect the error is reported; there is no exemption for that.
- Reads through other dynamic means, such as
sys.exc_info()or a template that receiveslocals()without naming the key, are not seen as uses.
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 FileNotFoundError as exc: # skylos: ignore[SKY-L005] kept for pdb[tool.skylos] ignore = ["SKY-L005"]turns the rule off for the project.