getsentry / getsentry/sentry

Exception type too broad in error handling

Open
#119,597 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Product Area: Other python Waiting for: Product Owner
Dominant language
Python
Stars
44.8k
Forks
4.9k
Avg merge
21h 23m
Merged PRs (30d)
607

Description

Bug Report

Description

Some except clauses catch overly broad exception types (e.g., bare except: or except Exception:), which can accidentally swallow important errors like KeyboardInterrupt or SystemExit.

Example
# Problematic:
try:
    do_something()
except:  # catches EVERYTHING including KeyboardInterrupt
    pass

# Better:
try:
    do_something()
except ValueError as e:
    logger.warning(f"Value error: {e}")
Expected Behavior

Exception handlers should catch only the specific exceptions they know how to handle.

Impact
  • Makes it impossible to interrupt the program with Ctrl+C in some cases
  • Hides unexpected errors that should be investigated
  • Makes debugging significantly harder
Suggested Fix

Replace broad except clauses with specific exception types wherever possible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are identified. Start by searching the Python source for bare except: and except Exception: clauses, then inspect each handler to determine which failures it intentionally handles. Done means replacing only justified broad catches with specific exception types and adding or updating coverage for the affected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.