Skip to content

Extend the silent-catch gate: promise-form handlers and literal false positives #213

Closed

Description

@hsliuustc0106

Follow-ups from the #205 review of PR #210, both non-blocking there:

  1. Promise-form silent catches stay ungated by design. The Silent catches: a bare catch{} swallows the error with no reason on record #205 gate covers the statement form only. The scanned sources carry ~198 .catch( handlers, some bare non-void swallows (e.g. core/src/host/diagnostics.js:222, :237, :246; core/src/host/store.js:454; core/src/host/agents.js:132-133). Decide the rule for the promise form — at minimum require a void prefix or a why-comment on a bare swallow — and extend check-empty-catch.mjs accordingly.

  2. Literal false positives. The text catch {} inside a comment or a string literal of a scanned file trips the gate (fail-safe: over-flags, never misses). Stripping comments/strings before matching closes it.

Where it sits: .github/scripts/check-empty-catch.mjs; its test file carries the cases.

Suggested direction: take the two separately — the promise-form rule needs a decision on the idiom's status first; the literal hardening is mechanical.

Activity

  1. Birfy commented on Oct 18, 2026

    @Birfy
    Collaborator

    Item 2 (literal false positives) is in #266: the gate blanks comments and the inside of strings, templates and regex literals before matching, so a catch {} written there is no longer reported. A } inside a string no longer cuts a block short either.

    Item 1 (promise form) needs a decision before anyone codes it. There are about 51 bare non-void .catch(() => {} | undefined | null) calls in the shipped sources.

    Proposed rule:

    • .catch(() => {}) whose result is dropped (a statement or an await statement) needs a void prefix or a why-comment.
    • .catch(() => undefined) / .catch(() => null) used as a value fallback (await x().catch(() => undefined) assigned or tested) stays allowed.

    Expected once decided: check-empty-catch.mjs flags only the first form, and the existing sites get a void prefix or a one-line reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions