Skip to content

Exception type too broad in error handling #8093

Description

@goransh-walia

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.

Activity

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