Bug

Errors swallowed to make it "work"

把错误吞掉,让它“能跑”

The agent wraps failing code in a catch that does nothing (or only logs) so the error disappears, and so does the signal that something is broken.

Applies to: Claude Code · Cursor · Codex · Copilot agent

Symptom

`catch (e) {}`, `except: pass`, `except Exception:` replacing a narrow handler, or a catch that returns `null` and lets bad data flow downstream.

Why it happens

A crash is a visible failure; a swallowed error makes the task look done and the test pass. agent-review lists AR017 (silent or swallowed catch) and AR019 (broad exception catch), noting agents widen catches to make tests pass when the real failure is upstream.

Example

From the agent-review taxonomy (AR017).

js
try { fn() } catch (e) { /* swallow */ }

Copy-paste fixes

Pick the files for the agents you use. Snippets are in English so they work in any repo.

Rules

Claude Code: add to CLAUDE.md

CLAUDE.md
## Don't hide errors
- Never add an empty catch, `except: pass`, or a catch that only logs and continues, unless the user asked
  for it and you comment why the error is safe to ignore.
- Catch the narrowest error type you can handle, and handle it (retry, fallback with a visible signal,
  or rethrow with context).
- If an error appears while you work, find its cause. Do not wrap it to make it go away.
Rules

Codex, Copilot coding agent and others: add to AGENTS.md

AGENTS.md
## Don't hide errors
- Never add an empty catch, `except: pass`, or a catch that only logs and continues, unless the user asked
  for it and you comment why the error is safe to ignore.
- Catch the narrowest error type you can handle, and handle it (retry, fallback with a visible signal,
  or rethrow with context).
- If an error appears while you work, find its cause. Do not wrap it to make it go away.
Cursor rule

Cursor: project rule

.cursor/rules/swallowed-error.mdc
---
description: "AgentFails: Errors swallowed to make it 'work'"
alwaysApply: true
---

## Don't hide errors
- Never add an empty catch, `except: pass`, or a catch that only logs and continues, unless the user asked
  for it and you comment why the error is safe to ignore.
- Catch the narrowest error type you can handle, and handle it (retry, fallback with a visible signal,
  or rethrow with context).
- If an error appears while you work, find its cause. Do not wrap it to make it go away.
CI / script

Lint rules that catch it (ESLint / Ruff)

eslint.config.mjs / pyproject.toml
// eslint.config.mjs
rules: { "no-empty": ["error", { allowEmptyCatch: false }] }

# pyproject.toml (ruff)
[tool.ruff.lint]
extend-select = ["E722", "BLE001", "S110"]  # bare except, blind except, try-except-pass

Sources and credit

Related patterns

翻车 of the week

One real agent failure and its fix, every week. Free, short, no spam.