-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Summary
There are 7 instances of bare except: clauses throughout the codebase that catch ALL exceptions including KeyboardInterrupt and SystemExit. This is a Python anti-pattern that prevents proper program termination and can hide critical errors.
Impact
Severity: Medium
Type: Code Quality / Reliability
Bare except: clauses can:
- Prevent users from gracefully terminating the program with Ctrl+C (
KeyboardInterrupt) - Hide system exit signals (
SystemExit) - Mask unexpected errors that should propagate
- Make debugging significantly harder
Affected Files
-
pdd/fix_errors_from_unit_tests.py:88, 95
- Silently ignores errors when cleaning up temporary files
try: os.unlink(tmp_path) except: # BAD: Catches KeyboardInterrupt, SystemExit, etc. pass
-
pdd/construct_paths.py:266
- Hides git repository detection failures
try: import git repo = git.Repo(file_path, search_parent_directories=True) repo_root = repo.working_tree_dir except: # BAD: Should catch specific git exceptions repo_root = os.getcwd()
-
pdd/update_main.py:65
- Swallows git errors without logging
try: import git repo = git.Repo(code_dir, search_parent_directories=True) repo_root = repo.working_tree_dir except: # BAD: No logging of actual error pass
-
pdd/unfinished_prompt.py:108
- Hides print/rprint errors
try: rprint(f"Input text: {prompt_text}") except: # BAD: If rprint fails, should know why print(f"Input text: {prompt_text}")
-
pdd/setup_tool.py:293
- Swallows shell detection errors
try: shell_path = os.getenv('SHELL', '/bin/bash') shell_name = os.path.basename(shell_path) return shell_name except: # BAD: os.path.basename shouldn't fail on valid input return 'bash'
-
pdd/agentic_common.py:549
- Hides JSON parsing errors
try: data = json.loads(lines[-1]) except: # BAD: Should be json.JSONDecodeError pass
Recommended Fix
Replace all bare except: clauses with specific exception types:
# Instead of:
try:
os.unlink(tmp_path)
except:
pass
# Use:
try:
os.unlink(tmp_path)
except (OSError, FileNotFoundError):
pass # File already deleted or doesn't exist
# Or for cleanup:
try:
os.unlink(tmp_path)
except Exception as e:
# Still allows KeyboardInterrupt and SystemExit to propagate
passReferences
- PEP 8 - Programming Recommendations: "Bare except: clauses will catch SystemExit and KeyboardInterrupt exceptions"
- Python Best Practices
Steps to Reproduce
- Run any PDD command that triggers these code paths
- Press Ctrl+C during execution
- Observe that some cleanup handlers may prevent graceful termination
Additional Context
While most of these are in cleanup/fallback code where the impact is lower, it's still best practice to catch specific exceptions. This makes the code more maintainable and helps identify unexpected error conditions during development.