SKY-L007 · Logic and resilience
Empty error handler
An error handler whose body does nothing: except Exception: pass, a with contextlib.suppress(Exception): block, or an empty catch {} in TypeScript or JavaScript. The error is caught and thrown away, and nothing records that it happened.
- Languages
- Python, TypeScript, JavaScript
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
Why it matters
The failure disappears. In the example below a database outage means no sign-in is written to the audit log, and nobody finds out until an investigation needs a record that was never stored.
What Skylos flags
"""Write audit events for sign-ins.""" import logging logger = logging.getLogger(__name__) def record_login(db, user_id, ip_address): try: db.insert("audit_log", {"user": user_id, "ip": ip_address, "event": "login"}) except Exception: passWhat Skylos leaves alone
"""Write audit events for sign-ins.""" import logging logger = logging.getLogger(__name__) def record_login(db, user_id, ip_address): try: db.insert("audit_log", {"user": user_id, "ip": ip_address, "event": "login"}) except ConnectionError: passWhy Skylos leaves it alone
The handler is still empty, but it names one specific error. Skylos treats a narrow exception type with a pass or placeholder body as a deliberate fallback: the author chose which failure to ignore. Only Exception, BaseException and a bare except: count as broad.
More languages
TypeScript
Flagged
import { audit } from "./audit";import { db } from "../db"; export async function saveProfile(userId: string, profile: object): Promise<void> { try { await audit.record("profile.update", userId); } catch (err) { } await db.profiles.update(userId, profile);}Not flagged
import { audit } from "./audit";import { db } from "../db"; export async function saveProfile(userId: string, profile: object): Promise<void> { try { await audit.record("profile.update", userId); } catch { // best effort: the audit service may be down } await db.profiles.update(userId, profile);}Why Skylos leaves it alone
The comment says why the error is ignored. Skylos reads comments in an empty catch and stays quiet when one documents the choice, with words such as "best effort", "expected", "fallback", "optional" or "ignore".
How Skylos decides
- Runs with
--quality. In Python it visits everyexceptclause and everywithstatement. - A Python handler is reported when its body is trivial: only
pass,continue,..., a bare string, or areturnofNone,""or an empty[],{},(),set(),list(),dict()ortuple(). Any other statement, such as a call or an assignment, means the handler does something and is not reported. - Skips handlers that name only specific exception types (anything other than
ExceptionorBaseException), and handlers forKeyboardInterruptorSystemExit. A handler that logs through a namelogger,loggingorlog, or that raises, is never reported. - Skips a broad handler that returns a placeholder; SKY-L030 reports that case. A bare
except:that returns a placeholder is reported here as HIGH; other trivial handlers are MEDIUM. - Reports
with contextlib.suppress(Exception)orsuppress(BaseException)as MEDIUM on thewithline. - Skips handlers and
suppressblocks inside afinallywhose body only deletes a temporary path (os.remove,os.unlink,shutil.rmtree,Path.unlinkand similar), unless they also swallowBaseExceptionor a bareexcept:. - In TypeScript and JavaScript files it reports a
catchblock that holds no statements (comments do not count) as MEDIUM on thecatchline. It skips test, Cypress, e2e, fixture, mock and Storybook files, generated files, acatchwhose parameter starts with_, atrythat is followed at once byreturnorthrow, and a block whose comment documents the choice, unless the comment says TODO, FIXME or "do not ignore".
How to fix it
Record the failure. Logging with the traceback keeps the sign-in working and leaves evidence that the audit write was lost. If the caller must know, re-raise instead.
"""Write audit events for sign-ins.""" import logging logger = logging.getLogger(__name__) def record_login(db, user_id, ip_address): try: db.insert("audit_log", {"user": user_id, "ip": ip_address, "event": "login"}) except Exception:Removed: passAdded: logger.exception("could not write the login audit event for %s", user_id)When it can be wrong
- A broad handler that really should ignore every error, such as a best-effort metrics call, is reported. Python comments are not read, so a comment that explains the choice does not help there; use the marker below.
- It misses
except ValueError: passand other narrow empty handlers, even when they hide a real problem.
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 (in TypeScript and JavaScript,// skylos: ignore[SKY-L007]on thecatchline).Python except Exception: # skylos: ignore[SKY-L007] metrics are best effort[tool.skylos] ignore = ["SKY-L007"]turns the rule off for the project.