Skip to main content

SKY-L007 · Logic and resilience

Empty error handler

Varies

The catalog gives no severity. Python reports HIGH for a bare except: whose body only returns a placeholder such as None, and MEDIUM for every other case. TypeScript and JavaScript always report MEDIUM.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

accounts/audit.py · PythonReported on line 11
"""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:        pass

What Skylos leaves alone

accounts/audit.py · Python
"""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:        pass

Why 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

src/profile/save.ts · TypeScriptReported on line 7
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

src/profile/save.ts · TypeScript
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

  1. Runs with --quality. In Python it visits every except clause and every with statement.
  2. A Python handler is reported when its body is trivial: only pass, continue, ..., a bare string, or a return of None, "" or an empty [], {}, (), set(), list(), dict() or tuple(). Any other statement, such as a call or an assignment, means the handler does something and is not reported.
  3. Skips handlers that name only specific exception types (anything other than Exception or BaseException), and handlers for KeyboardInterrupt or SystemExit. A handler that logs through a name logger, logging or log, or that raises, is never reported.
  4. 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.
  5. Reports with contextlib.suppress(Exception) or suppress(BaseException) as MEDIUM on the with line.
  6. Skips handlers and suppress blocks inside a finally whose body only deletes a temporary path (os.remove, os.unlink, shutil.rmtree, Path.unlink and similar), unless they also swallow BaseException or a bare except:.
  7. In TypeScript and JavaScript files it reports a catch block that holds no statements (comments do not count) as MEDIUM on the catch line. It skips test, Cypress, e2e, fixture, mock and Storybook files, generated files, a catch whose parameter starts with _, a try that is followed at once by return or throw, 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.

accounts/audit.py · Python · the fix, against the flagged file
"""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: pass and 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 except line (in TypeScript and JavaScript, // skylos: ignore[SKY-L007] on the catch line).

    Python
    except Exception:  # skylos: ignore[SKY-L007] metrics are best effort
  • [tool.skylos] ignore = ["SKY-L007"] turns the rule off for the project.

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