Skip to content

Remove try-catch blocks from AdPentest.aspx - #74

Open
netanelcyber wants to merge 1 commit into
claude/pentesting-active-directory-bfghhzfrom
claude/project-thread-obn601
Open

netanelcyber wants to merge 1 commit into
claude/pentesting-active-directory-bfghhzfrom
claude/project-thread-obn601

Conversation

@netanelcyber

Copy link
Copy Markdown
Owner

Requested by NETANEL · project thread

Before: 14 try-catch blocks scattered through the main code paths — bImport_Click, SaveAndDisplayAsync, BindHistoryAsync, LoadReportAsync, and StopProcessTreeAsync all wrapped in broad exception handlers, with empty catch {} blocks and nested try-catch chains.

After: Main code paths use guard clauses and early returns instead of try-catch. Remaining 7 catch blocks are isolated in small, focused helper methods (TrySaveUniqueAsync, IsProcessRunning, TryPopulateImport, TryPopulateReport, TryMarkRowErrorAsync) or genuinely required (background task error recording, semaphore cleanup).

The refactoring replaces exception-based control flow with explicit conditionals: validation in bImport_Click now uses early returns, SaveAndDisplayAsync uses ShowMessage + return at each error path, and StopProcessTreeAsync uses an IsProcessRunning guard instead of nested try-catch-catch chains.

How: Extracted five helper methods that encapsulate the unavoidable catch blocks (process management, DB constraint races, JSON parsing). Removed the wrapping try-catch from BindHistoryAsync and LoadReportAsync entirely. Replaced the cancellation-token registration's inline try-catch with an IsProcessRunning guard.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ni4YjEC33HpqKZxGw6gMu


Generated by Claude Code

- bImport_Click: replace try-catch with guard clauses and early returns
  for validation; extract TryPopulateImport helper for parse errors
- SaveAndDisplayAsync: remove outer try-catch, use early returns with
  ShowMessage + ShowReport for each error path
- BindHistoryAsync / LoadReportAsync: remove wrapping try-catch entirely
- StopProcessTreeAsync: replace nested try-catch with IsProcessRunning
  guard and specific Win32Exception catch on Process.Start only
- Cancellation registration: remove try-catch, use IsProcessRunning guard
- bRun_Click error recovery: extract TryMarkRowErrorAsync helper
- DB unique constraint: extract TrySaveUniqueAsync helper, reuse in both
  RunScanBackgroundAsync and SaveAndDisplayAsync
- Extract TryPopulateReport helper for background scan JSON parsing

Reduces catch blocks from 14 to 7, with remaining ones isolated in
small, focused helper methods or genuinely required (background task
error recording, semaphore cleanup).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ni4YjEC33HpqKZxGw6gMu
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@netanelcyber netanelcyber self-assigned this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants