Skip to main content

silentcatch

Fails your build when a pull request introduces an exception handler that swallows failures.

def verify_password(user, password):
    try:
        return hash_password(password) == user.password_hash
    except Exception:
        return True          # <- everyone gets in

Tests pass. Linters pass. Type checkers pass. The function returns a bool, as declared.

Why this exists

Static analysis is good at the things that are visibly wrong. Swallowed exceptions are not visibly wrong. The code runs, returns a plausible value, and logs nothing. You find out weeks later, from a number that does not reconcile.

This has always been a problem. It got worse when code started being generated faster than it gets read, because a model asked to "handle the error" will reliably produce a handler that makes the error go away rather than one that surfaces it.

The fix is not more review. It is making the codebase refuse the pattern.

What it flags

Failures (exit 1):

  • A handler whose body is pass
  • A handler that returns a fallback value without logging or re-raising
  • A handler that does something unrelated and never records the error

Warnings (exit 0 unless --strict):

  • A broad handler (except Exception, bare except) that logs but does not re-raise

The second category is deliberately a warning. Catching broadly and logging is sometimes correct, at a request boundary or a task runner. It is worth seeing, not worth blocking.

What it does not flag

  • Narrow handlers that log. except ValueError: logger.warning(...) is a considered decision.
  • Anything that re-raises, bare or chained.
  • Handlers reporting to Sentry and similar (capture_exception, report, notify).
  • Anything marked # silentcatch: allow.

Install

pip install silentcatch

Use

# whole project
silentcatch .

# just one package
silentcatch src/

# only lines changed in this PR
silentcatch --base origin/main

# also fail on broad handlers that log but do not re-raise
silentcatch --strict

Exit code is 1 if anything failed, 0 otherwise.

GitHub Action

name: silentcatch

on: [pull_request]

jobs:
  silentcatch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0          # needed for --base
      - uses: ikramulmustafa/silentcatch@v1
        with:
          base: origin/${{ github.base_ref }}

Findings appear as inline annotations on the diff.

--base matters on an existing codebase. Without it the first run surfaces every handler you have ever written, the check gets disabled, and nothing improves. Diff mode holds new code to the standard and leaves the backlog alone.

Suppressing

Some handlers genuinely should swallow. Optional telemetry, best-effort cache warming, cleanup in a finally path.

try:
    telemetry.send(event)
except Exception:  # silentcatch: allow
    pass

The comment goes on the except line or the line above it. Requiring an explicit marker is the point: the decision gets made once, in writing, where a reviewer can see it.

Limitations

Worth knowing before you adopt it.

  • Python only. The approach ports to other languages; this implementation does not.
  • Logger detection is heuristic. It matches method names (error, warning, exception) against plausible receivers (logger, log, self). A custom logging wrapper with an unusual name will not be recognised, and you will get a false positive.
  • It cannot tell intent. A handler that returns a safe default because that genuinely is the right behaviour looks identical to one that hides a bug. That is why the suppression comment exists rather than a cleverer rule.
  • Single-file analysis. No cross-module awareness. If your handler calls a helper that logs, that is not detected.

The false positive rate is the thing to watch. A check that fires on correct code gets disabled, and a disabled check is worth less than no check.

How it works

Parses each file with ast, walks every ExceptHandler, and inspects the body for evidence the failure was recorded: a raise, a logging call, or a reporting call. No evidence means the exception is being swallowed.

Roughly 200 lines. No dependencies beyond the standard library.

Contributing

Issues and pull requests welcome. False positives are the most useful thing you can report: a real handler it flagged that it should not have, with the code.

Licence

MIT

Metadata

Release files for silentcatch 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for silentcatch 0.1.0
File Size Uploaded Provenance Actions
silentcatch-0.1.0.tar.gz 10.7 kB Without provenance Details for silentcatch-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for silentcatch 0.1.0
File Interpreter ABI Platform Actions
silentcatch-0.1.0-py3-none-any.whl Python 3 none any Details for silentcatch-0.1.0-py3-none-any.whl

Total release size: 19.3 kB

Release files / silentcatch-0.1.0.tar.gz

Download URL silentcatch-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
401deefc4de2fde30c9858934245f1decaae81101b5ef18e41e262bc3445a305
BLAKE2b-256 checksum
How to use checksums
a950f0c831cd4fdf51f4b308838f68ee8a7cb5e0d4416bd9847fa7a78e01a0c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / silentcatch-0.1.0-py3-none-any.whl

Download URL silentcatch-0.1.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
271aafa086291e534b80485d622a1e1fa3ed51daa8e85bbc7e598b78f60c97bd
BLAKE2b-256 checksum
How to use checksums
5cb58b27ec57862bc9fd7955e8e4a4d64e1af28ed91df83e88bcd1dec9b736d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for silentcatch 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page