Skip to content

[SECURITY] Replace 14 bare except blocks in pt_hub.py - closes #53#91

Merged
sjackson0109 merged 4 commits into
sjackson0109:mainfrom
Ibrahim-3d:feat/53-bare-except-audit
May 21, 2026
Merged

[SECURITY] Replace 14 bare except blocks in pt_hub.py - closes #53#91
sjackson0109 merged 4 commits into
sjackson0109:mainfrom
Ibrahim-3d:feat/53-bare-except-audit

Conversation

@Ibrahim-3d

Copy link
Copy Markdown
Collaborator

Summary

Replaces all 14 bare except: blocks in pt_hub.py. Bare except: incorrectly swallows SystemExit and KeyboardInterrupt.

Lines Replacement Reason
4303-4638 (9 blocks) except Exception: GUI tab creation, multiple possible exception types
5548 except (TimeoutError, OSError): proc.communicate(timeout=1)
5597 except (OSError, AttributeError): proc.stdout.read()
5680, 5769, 5906 except Exception: Widget/color/training utilities

pt_trader.py had 0 bare except: (only broad except Exception: which was acceptable).

Changes

  • Modified: app/pt_hub.py — 14 substitutions, zero functional changes

Test plan

  • flake8 --select=E9,F63,F7,F82 - zero hard errors after change
  • grep "except:" pt_hub.py - zero results

Closes #53

Copilot AI review requested due to automatic review settings May 18, 2026 16:10
@Ibrahim-3d Ibrahim-3d requested a review from sjackson0109 as a code owner May 18, 2026 16:10
GUI tab creation bare excepts (lines 4303-4638): except Exception:
Process communicate timeout (line 5548): except (TimeoutError, OSError):
Stdout read failure (line 5597): except (OSError, AttributeError):
Widget/color utilities (lines 5680-5906): except Exception:

Bare except: swallows SystemExit and KeyboardInterrupt. All 14 replaced.
pt_trader.py had 0 bare except: (only broad except Exception: which is
acceptable given its error handling patterns).
@Ibrahim-3d Ibrahim-3d force-pushed the feat/53-bare-except-audit branch from 5f94349 to e37c21d Compare May 18, 2026 18:37
@sjackson0109 sjackson0109 self-assigned this May 18, 2026
@sjackson0109 sjackson0109 added code-quality error-handling component-architecture System architecture and design components labels May 18, 2026
@Ibrahim-3d

Copy link
Copy Markdown
Collaborator Author

Manual Testing Guide — PR #91: Replace Bare Except Blocks in pt_hub.py

Prerequisites

git fetch fork && git checkout feat/53-bare-except-audit
cd app

1. Confirm no bare excepts remain in pt_hub.py

python -c "
import ast, sys
with open('pt_hub.py') as f:
    tree = ast.parse(f.read())
bare = [n.lineno for n in ast.walk(tree)
        if isinstance(n, ast.ExceptHandler) and n.type is None]
if bare:
    print('FAIL: bare excepts at lines:', bare)
    sys.exit(1)
print(f'PASS: 0 bare excepts (was 14)')
"

2. Run existing tests to confirm no regressions

python -m pytest test_comprehensive.py -v --timeout=30 -k "not gui"

Expected: All non-GUI tests pass.

3. Smoke test — start the hub (headless check)

python -c "import pt_hub; print('import ok')"

Expected: Imports without errors.

Rollback

git checkout main -- app/pt_hub.py

Ibrahim-3d and others added 2 commits May 19, 2026 15:29
Black check failed in CI — pt_hub.py had formatting issues.
Auto-formatted with Black.
@sjackson0109 sjackson0109 merged commit 26e2b39 into sjackson0109:main May 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality component-architecture System architecture and design components error-handling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SECURITY] Replace bare except blocks with proper error handling

2 participants