Skip to content

fix: narrow all CA1031 catch blocks in UI.Slim to specific types#533

Merged
rygel merged 3 commits intomainfrom
fix/ca1031-ui-slim
Apr 5, 2026
Merged

fix: narrow all CA1031 catch blocks in UI.Slim to specific types#533
rygel merged 3 commits intomainfrom
fix/ca1031-ui-slim

Conversation

@rygel
Copy link
Copy Markdown
Owner

@rygel rygel commented Apr 5, 2026

Summary

Replace 63 generic catch (Exception) blocks across 19 UI.Slim files. CA1031 is now zero across the entire solution.

Async void event handlers (42 catches): Use when (ex is not OperationCanceledException) — prevents app crashes from unhandled async void exceptions while letting cancellation propagate safely.

Synchronous utility methods (6 catches): Narrowed to specific types:

  • GetForegroundWindowSummary: ArgumentException, InvalidOperationException, Win32Exception
  • BrowserService.OpenUrl: InvalidOperationException, Win32Exception, IOException
  • UIHelper.GetResourceBrush: InvalidOperationException, XamlParseException

File I/O (4 catches): IOException, UnauthorizedAccessException

Resource loading (3 catches): IOException, InvalidOperationException, NotSupportedException

Info dialog (4 catches): Mix of file I/O, process launch, and async void patterns

App startup (2 catches): when (ex is not OperationCanceledException)

Test plan

  • dotnet build — 0 CA1031 warnings in entire solution
  • 1122/1126 tests pass (4 pre-existing file-lock flakes)

🤖 Generated with Claude Code

actions-user and others added 3 commits April 5, 2026 10:26
Replace 17 generic catch(Exception) blocks with specific exception
type filters across 8 Monitor service files:

- Config/preferences I/O: IOException, UnauthorizedAccessException, JsonException
- Import (CSV/JSON + SQLite): IOException, JsonException, FormatException, SqliteException
- Job scheduler: catch all except OperationCanceledException (background job runner)
- Provider refresh: HttpRequestException, TaskCanceledException, JsonException, IOException
- Startup seeding: IOException, JsonException, InvalidOperationException
- Usage alerts: IOException, InvalidOperationException
- Monitor info persistence: IOException, UnauthorizedAccessException, JsonException
- Auth diagnostics: IOException, UnauthorizedAccessException

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace 63 generic catch(Exception) blocks across 19 UI.Slim files:

- Async void event handlers (_Click, _Checked, _Loaded, timer ticks):
  catch (Exception ex) when (ex is not OperationCanceledException)
  Prevents app crashes from unhandled async void exceptions while
  letting cancellation propagate safely.

- Synchronous utility methods (GetForegroundWindowSummary, OpenUrl,
  GetResourceBrush): narrowed to specific Win32Exception,
  InvalidOperationException, IOException as appropriate.

- File I/O helpers (UiDiagnosticFileLog): IOException,
  UnauthorizedAccessException only.

- Resource loading (WpfProviderIconService, GetProviderImageSource):
  IOException, InvalidOperationException, NotSupportedException.

CA1031 is now zero across the entire solution (Core, Infrastructure,
Monitor, UI.Slim).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rygel rygel merged commit 107789a into main Apr 5, 2026
19 of 20 checks passed
@rygel rygel deleted the fix/ca1031-ui-slim branch April 5, 2026 07:57
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