fix: narrow all CA1031 catch blocks in UI.Slim to specific types#533
Merged
fix: narrow all CA1031 catch blocks in UI.Slim to specific types#533
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,Win32ExceptionBrowserService.OpenUrl:InvalidOperationException,Win32Exception,IOExceptionUIHelper.GetResourceBrush:InvalidOperationException,XamlParseExceptionFile I/O (4 catches):
IOException,UnauthorizedAccessExceptionResource loading (3 catches):
IOException,InvalidOperationException,NotSupportedExceptionInfo 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🤖 Generated with Claude Code