Skip to content

Code review: 10+ bare except clauses detected #2

@Fujun-0807

Description

@Fujun-0807

Hi @Skillter,

Follow-up to the previous security finding, I also noticed multiple instances of bare except: clauses across the codebase:

🔍 Findings

Issue: Bare except clauses (BUG002)
Severity: Medium
Locations:

  • Line 80, 96, 114, 123, 153, 173, 199, 208, 269, 365

💡 Why it matters

Bare except: catches everything, including:

  • SystemExit (when user presses Ctrl+C)
  • KeyboardInterrupt
  • GeneratorExit

This can make debugging difficult and mask real issues.

✅ Suggested fix

# Instead of:
try:
    do_something()
except:  # ❌ Too broad
    pass

# Use:
try:
    do_something()
except Exception as e:  # ✅ Specific
    logger.error(f"Failed to do something: {e}")
    # or re-raise if needed
    raise

If you need to catch everything intentionally, at least log the error:

except Exception as e:
    logger.exception("Unexpected error: %s", e)

Tool used

Code Guardian – 183-line code review tool with 7 core rules.

Happy coding!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions