CodeQL 5: refactor(ClinicalScheduler): catch specific exceptions in services#193
CodeQL 5: refactor(ClinicalScheduler): catch specific exceptions in services#193rlorenzo wants to merge 2 commits into
Conversation
CodeQL cs/catch-of-all-exceptions: replace blanket `catch (Exception)` in 8 ClinicalScheduler service files with a `when` filter restricting to the exception families these methods actually need to wrap (DbUpdateException, SqlException, InvalidOperationException, OperationCanceledException). Anything outside that set now propagates unchanged. Four fire-and-forget catches around post-transaction work (email notifications and audit logging that must not roll back successful DB changes) are kept intentionally broad and marked with `#pragma warning disable CA1031` explaining why. Test EmailNotificationTest.RemoveInstructorScheduleAsync_EmailServiceFails_StillCompletesRemoval enforces this resilience contract.
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle ReportBundle size has no change ✅ |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #193 +/- ##
=======================================
Coverage 42.96% 42.96%
=======================================
Files 877 877
Lines 51468 51468
Branches 4802 4802
=======================================
Hits 22113 22113
Misses 28831 28831
Partials 524 524
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ReSharper RedundantNameQualifier flagged all 45 occurrences of Microsoft.EntityFrameworkCore.DbUpdateException and Microsoft.Data.SqlClient.SqlException in the when-filtered catches introduced by codeql/5. Replaced with the unqualified type names; 'using Microsoft.Data.SqlClient;' added to the 7 files that didn't already have it.
Summary
Closes ~39 of 43
cs/catch-of-all-exceptionsalerts inweb/Areas/ClinicalScheduler/Services/**. Replaces blanketcatch (Exception)with awhenfilter that restricts to the exception families these service methods actually need to wrap (DbUpdateException,SqlException,InvalidOperationException,OperationCanceledException) per the CLAUDE.md convention.Why 4 broad catches are kept
Four catches wrap fire-and-forget post-transaction work - email notifications and audit logging that must run after a successful DB change and must not roll the change back. The
EmailNotificationTest.RemoveInstructorScheduleAsync_EmailServiceFails_StillCompletesRemovaltest enforces this resilience contract by throwing a rawExceptionfrom the mocked email service and asserting that the schedule removal still succeeds. These four sites are kept broad and explicitly annotated:CodeQL will still flag these four; they're known-intentional and can be dismissed in the dashboard.
Files changed
InstructorScheduleService.cs- 1 catch narrowedPersonService.cs- 6 catches narrowedRotationService.cs- 7 catches narrowedScheduleAuditService.cs- 3 catches narrowedScheduleEditService.cs- 9 narrowed, 4 kept broad with pragmaSchedulePermissionService.cs- 8 catches narrowedStudentScheduleService.cs- 1 catch narrowedWeekService.cs- 4 catches narrowedContext
Fifth in the
CodeQL N:cleanup series (after #189, #190, #191, #192).Test plan
npm run test:backend- 1946 tests passing (including the email-failure resilience test)npm run verify:build- clean (0 errors)