Skip to content

CodeQL 15: chore(tests): narrow catch(Exception) to specific types in test helpers#201

Open
rlorenzo wants to merge 2 commits into
mainfrom
codeql/15-pdf-select-conversion
Open

CodeQL 15: chore(tests): narrow catch(Exception) to specific types in test helpers#201
rlorenzo wants to merge 2 commits into
mainfrom
codeql/15-pdf-select-conversion

Conversation

@rlorenzo
Copy link
Copy Markdown
Contributor

@rlorenzo rlorenzo commented May 13, 2026

Summary

Closes 5 of the remaining cs/catch-of-all-exceptions alerts in test code by narrowing the catch to the specific types each test helper is actually expecting:

  • test/CTS/AssessmentControllerTest.cs:266,282 - IsForbidResult / IsNotFoundResult helpers convert xUnit assertion failures to false. Narrowed from catch (Exception) to catch (Xunit.Sdk.XunitException), which is exactly what Assert.X(...) throws.
  • test/ClinicalScheduler/EmailNotificationTest.cs:284,466 - diagnostic try/catch around RemoveInstructorScheduleAsync. Narrowed to when (ex is InvalidOperationException or DbUpdateException or SqlException or OperationCanceledException) - the actual exception families that production code throws (matches the service's when filter from CodeQL 5: refactor(ClinicalScheduler): catch specific exceptions in services #193).
  • test/ClinicalScheduler/RotationServiceTest.cs:98 - test-data-seeding try/catch around SaveChanges. Narrowed to when (ex is DbUpdateException or InvalidOperationException).

Context

Fifteenth in the CodeQL N: cleanup series. (The PDF/Excel cs/linq/missed-select Select-conversion attempted on this branch was reverted - the script over-matched loops where the iter var is also used in headers/totals/spacers, breaking compilation. Those remaining 19 alerts genuinely require the iter var and can't be cleanly converted.)

Test plan

  • npm run test:backend - 1946 tests passing
  • Pre-commit lint+test+verify all passed

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • review-ready

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f30c21b4-451c-41b8-94cf-2b888ea68032

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codeql/15-pdf-select-conversion

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.96%. Comparing base (38de1ad) to head (33c47fb).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #201   +/-   ##
=======================================
  Coverage   42.96%   42.96%           
=======================================
  Files         877      877           
  Lines       51468    51468           
  Branches     4802     4802           
=======================================
  Hits        22113    22113           
  Misses      28831    28831           
  Partials      524      524           
Flag Coverage Δ
backend 43.04% <ø> (ø)
frontend 41.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…ilters

Removed 'Microsoft.EntityFrameworkCore.' and 'Microsoft.Data.SqlClient.'
prefixes from the catch when-filters added in codeql/15. Added
'using Microsoft.Data.SqlClient;' to EmailNotificationTest.
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