Skip to content

feat(cli): blind exception handling policy #423

Closed as not planned
Closed as not planned

Description

@dan-petty

Decision (owner, 2026-10-22)

This section replaces any text below that conflicts with it. It folds in the item "ci(lint): new swallowed failures, over-cap functions and suppressions fail per changed line, replacing the C901 ceiling and the swallowed-failures baseline".

Gate

  • A diff-quality row in devops ci fails any changed line that adds a violation of C901, BLE001, S110, S112, E402, F401, SIM115, UP036 or N803. The row uses --ignore-noqa. A new site fails even when it carries a reason. The row needs no baseline file.
  • The 488 existing sites (414 BLE001, 57 S110, 17 S112) need no edit.
  • The baseline tests/fixtures/swallowed_failures_ceilings.json, tests/test_swallowed_failures_ratchet.py and the seven Ruff noqa ceilings are deleted.
  • The 29 unread check=False sites become check=True with handling of CalledProcessError. An ast-grep rule bans check=False.

Plan for the BLE rules

  1. The gate lands. A new blind handler fails the pull request.
  2. Each pull request that touches a file with a site fixes the site. The fix narrows the exception tuple, or handles the error. Best-effort cleanup narrows to the exceptions it can meet, for example OSError. Cluster pull requests burn down the rest, one package at a time.
  3. When the count is 0, add BLE001, S110 and S112 to select in pyproject.toml. Remove them from the --select list of the diff row.
  4. The CLI boundary of the exception item (refactor(exceptions): validators and library calls raise their own exceptions, the CLI boundary maps them and DevOpsCLIError bounds details once) is the one handler that stays broad.

Changes to the criteria below

  • Criterion 1 (triage of the 501 sites) continues in the burn-down pull requests. It does not block the gate.
  • Criterion 3 (a # noqa: BLE001 with a reason on each retained handler) no longer applies. A blind handler on a changed line fails the gate.
  • Criterion 5 (BLE001 as a hard rule) happens at step 3 of the plan.
  • Criterion 6 (updated ceilings) no longer applies. The baseline is deleted.

Tests

  • A tmp_path git repository with a base commit and a branch. A new except Exception: fails, and so does a new # noqa: C901 function. A compliant branch passes.
  • An ast-grep rule test for check=False.

Dependencies

  • refactor(ci): Ruff's own flags protect the complexity cap, and the configuration-escape tests and key allowlists are deleted

Acceptance criteria for this decision

  • A new except Exception: on a changed line fails devops ci, even with # noqa: BLE001.
  • The baseline file and the swallowed-failures test are gone. The 488 existing sites are unchanged.
  • No check=False remains in src/. The ast-grep rule reports 0 findings.
  • The pull request reports a replay of the gate over the last 20 merged pull requests.
  • uv run devops ci passes.

Context & Rationale

501 BLE001 sites exist across src/, of which 77 are except Exception: pass. Some are legitimate best-effort cleanup; the problem is that nothing distinguishes those from the ones swallowing a defect, and a handler that has never been entered is indistinguishable from one that works. A handler in the workbench of the companion vibes repository referenced an undefined name and could only ever raise NameError; it survived precisely because no test forced the branch.

Scope & Deliverables

  • Context & Rationale*: 501 BLE001 sites exist across src/, of which 77 are except Exception: pass. Some are legitimate best-effort cleanup; the problem is that nothing distinguishes those from the ones swallowing a defect, and a handler that has never been entered is indistinguishable from one that works. A handler in the workbench of the companion vibes repository referenced an undefined name and could only ever raise NameError; it survived precisely because no test forced the branch.
  • Deliverable*: Enable BLE001, triage the surface, and require every retained blind handler to carry an explicit # noqa: BLE001 with a justification and to narrow its exception tuple where the failure modes are known. Every handler written to degrade gracefully needs a test that forces it.
  • Constraint*: Triage before enforcement. Turning the rule on against 501 sites without a policy produces one large suppression commit, which is the same silence with more ceremony.

Strategic Alignment

Proposed design

Problem statement

The codebase contains 501 BLE001 (blind exception handling) sites. Some are legitimate best-effort cleanup, but nothing distinguishes them from handlers that silently swallow real defects. A handler that has never been entered is indistinguishable from one that works.

Acceptance criteria

  • Criterion 1: A new except Exception: on a changed line fails devops ci, even with # noqa: BLE001.
    Verification: Run uv run devops ci and introduce a new except Exception: pass in a changed line; the CI should fail.
  • Criterion 2: The baseline file and the swallowed-failures test are gone. The 488 existing sites are unchanged.
    Verification: Verify that tests/fixtures/swallowed_failures_ceilings.json, tests/test_swallowed_failures_ratchet.py and the seven Ruff noqa ceilings are deleted, and the 488 existing sites remain unchanged.
  • Criterion 3: No check=False remains in src/. The ast-grep rule reports 0 findings.
    Verification: Run an ast-grep rule test for check=False and verify it reports 0 findings. Also confirm that no check=False exists in src/.
  • Criterion 4: The pull request reports a replay of the gate over the last 20 merged pull requests.
    Verification: Check that the pull request includes a replay of the gate over the last 20 merged pull requests as part of its CI checks.
  • Criterion 5: uv run devops ci passes.
    Verification: Run uv run devops ci and confirm it passes without any failures.

Key questions

  • Is BLE001 already counted by the existing swallowed-failures ratchet test?: Yes. Issue test(cli): swallowed failures may not grow: blind excepts, except-pass, except-continue and unread check=False are held at their ceilings #1347 (Done in v0.2.33) established tests/test_swallowed_failures_ratchet.py, which counts Ruff's BLE001, S110, and S112 findings per file against ceilings in tests/fixtures/swallowed_failures_ceilings.json. A file not listed has a ceiling of 0. [sources: CHANGELOG.md:19]
  • Is BLE001 already present in the review's advisory rule set?: Yes. Issue feat(review): ruff and mypy run as review evidence with the project's settings, advisory rules report only on changed lines, and changed functions show complexity before and after #873 (Done in v0.2.33) added BLE001 to .devops/review.toml's [advisory] rules, so reviews already surface it as an advisory finding on changed lines. [sources: CHANGELOG.md:17]
  • What is the triage policy for categorizing the 501 BLE001 sites?: Each site is categorized as one of: (a) legitimate best-effort cleanup where a broad catch is the correct design (suppress with justification), (b) a defect where the handler swallows a real error (fix by narrowing the tuple or adding proper handling), or (c) a handler whose exception tuple is broader than the failure modes it actually handles (narrow the tuple). The constraint is that triage must precede enforcement to avoid one large suppression commit. (proposed)
  • What format should the noqa suppression and its justification take?: Each retained site carries # noqa: BLE001 on the except line, followed by a comment that names the specific reason the broad catch is necessary (e.g., best-effort temp-file cleanup, optional dependency probe). The justification must be specific enough that a reviewer can judge whether the broad catch is warranted without reading the surrounding code. (proposed)
  • What test pattern is required for a handler written to degrade gracefully?: A test that raises the specific exception the handler catches (via a mock, fixture, or direct call) and asserts the handler's observable behavior: that it logs, returns a default value, continues execution, or otherwise degrades as designed. The test must force the except branch to execute; a test that only exercises the happy path does not satisfy the requirement. (proposed)

Open questions

  • Does this work depend on any other open issue? (missing verified source)

Fit

Needs splitting into 3 items:

  1. Triage: categorize all 501 BLE001 sites as legitimate, defect, or needs-narrowing, and record the policy decision for each
  2. Fix and test: narrow exception tuples at defect sites, add proper error handling where the handler was swallowing a real error, and write tests that force every graceful-degradation except branch to execute
  3. Suppress and enable: add # noqa: BLE001 with a justification comment at every legitimate site, update the ratchet ceilings in tests/fixtures/swallowed_failures_ceilings.json, and enable BLE001 as a hard rule in the project's Ruff configuration

Suspected block

None.

Dependencies

None.

Activity

  1. added this to the v0.2.23 milestone on Sep 22, 2026
  2. added
    type/feature
    scope/cli
    priority/p2-medium
    on Sep 22, 2026
  3. modified the milestones: v0.2.23, v0.2.25 on Sep 24, 2026
  4. dan-petty commented on Sep 30, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to the backlog. v0.2.25 is capped at 12 items (#740), and only the next two planned releases keep a milestone (#739), so P2 items wait in the backlog until reprioritization pulls them in.

  5. added
    type/refactor
    and removed
    type/feature
    on Oct 2, 2026
  6. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    More evidence for this issue from the devsecops review session 20261001-224227 (2026-10-02). Each finding below was triaged against release/v0.2.25 (c279c18), judged real and covered by this issue, and then upheld by a second agent that tried to refute it.

    • Catastrophic Exception Handling in Prometheus Exporter (src/devops_cli/ai/spend/prometheus.py:146, re-rated LOW): The handler is except Exception: return "" around active_ledger.get_lifetime_report(...) (139-147), with no log. A SQLite error, a pricing-registry failure or a plain bug makes devops ai cost prometheus (ai_cost.py:558-563) print nothing and exit 0. The /metrics route (server/routes/telemetry.py:87-89) silently drops every devops_cli_ai_* series. That is a real hidden failure but minor, not 'catastrophic'. Issue feat(cli): blind exception handling policy #423 (blind exception handling policy) covers exactly these except Exception swallow sites: narrow the tuple, justify, and test the degrade path. BLE001 is not enabled yet.
    • Exception handling bypasses all errors during AST parsing (src/devops_cli/ai/test_gen.py:74, re-rated LOW): try: tree = ast.parse(...) ... except Exception: pass (58-75) swallows a SyntaxError in the target. The function then falls through to the 'default_behavior' import test (77-83), and the CLI prints '✓ Synthesized 1 unit test(s)' (commands/ai.py:1933) for a file it could not parse. This is a real hidden failure with low impact (the status is already UNEXECUTED). It is one of the except Exception: pass sites that feat(cli): blind exception handling policy #423 (blind exception handling policy) triages. The generator itself is being reworked to scaffolds under fix(ai): devops ai test-gen stops reporting presence-only tests as synthesized unit tests #856.
  7. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #1347 holds BLE001, S110 and S112 at per-file ceilings until this item lowers them, and #849 counts the # noqa: BLE001 markers this item adds. Found by the 2026-10-08 backlog review.

  8. added this to the v0.2.35 milestone on Oct 9, 2026
  9. 5 remaining items

  10. modified the milestones: v0.2.38, on Oct 17, 2026
  11. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    Proposal needs splitting into 3 items at ae8c2d9 (see proposed design in issue body).

  12. removed this from the milestone on Oct 23, 2026
  13. dan-petty commented on Oct 23, 2026

    @dan-petty
    OwnerAuthor

    Proposal needs splitting into 3 items at 4bb052c (see proposed design in issue body).

  14. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Cancelled: policy is brittle with excessive maintenance friction across shallow checkouts and concurrent rebases.

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

    priority/p2-mediumscope/clitype/refactor

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions