Skip to content

Commit 39e16db

Browse files
committed
fix(ClinicalScheduler): correct catch filters in services
Two related fixes to the filtered catches added in c269ad7: 1. OperationCanceledException no longer swallowed. The filters caught cancellation alongside data-access failures, wrapping it as InvalidOperationException (or, in SchedulePermissionService, silently returning `false`/empty results). Dropping it from the `when` filters lets cooperative cancellation propagate naturally. 2. Unreachable types removed from three filters that listed exceptions already handled by a dedicated catch clause above them: - PersonService AddRangeInstructorScheduleAsync: SqlException is caught at the preceding `catch (SqlException ex)`. - ScheduleEditService AddInstructorScheduleAsync and RemoveInstructorScheduleAsync: InvalidOperationException is rethrown by the preceding `catch (InvalidOperationException)` passthrough.
1 parent f5dbd34 commit 39e16db

8 files changed

Lines changed: 39 additions & 39 deletions

File tree

web/Areas/ClinicalScheduler/Services/InstructorScheduleService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public async Task<List<InstructorSchedule>> GetInstructorScheduleAsync(
105105
_logger.LogInformation("Found {Count} instructor schedules", schedules.Count);
106106
return schedules;
107107
}
108-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
108+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
109109
{
110110
_logger.LogError(ex, "Error retrieving instructor schedules");
111111
throw new InvalidOperationException("Failed to retrieve instructor schedules", ex);

web/Areas/ClinicalScheduler/Services/PersonService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public PersonService(ILogger<PersonService> logger, ClinicalSchedulerContext con
8181

8282
return person;
8383
}
84-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
84+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
8585
{
8686
_logger.LogError(ex, "Error retrieving person data for MothraId: {MothraId}", LogSanitizer.SanitizeId(mothraId));
8787
throw new InvalidOperationException($"Failed to retrieve person data for MothraId {LogSanitizer.SanitizeId(mothraId)}", ex);
@@ -139,7 +139,7 @@ public async Task<List<ClinicianYearSummary>> GetCliniciansByYearAsync(int year,
139139
_logger.LogInformation("Found {ClinicianCount} clinicians for year {Year} with person names from vPerson view", clinicians.Count, year);
140140
return clinicians;
141141
}
142-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
142+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
143143
{
144144
_logger.LogError(ex, "Error retrieving clinicians for year: {Year}", year);
145145
throw new InvalidOperationException($"Failed to retrieve clinicians for grad year {year}. Check database connectivity and view permissions.", ex);
@@ -209,7 +209,7 @@ public async Task<List<ClinicianSummary>> GetCliniciansByGradYearRangeAsync(int
209209
_logger.LogError(ex, "Database error retrieving clinicians for grad year range {StartYear}-{EndYear}", LogSanitizer.SanitizeYear(startGradYear), LogSanitizer.SanitizeYear(endGradYear));
210210
throw new InvalidOperationException($"Database error retrieving clinicians for grad year range {LogSanitizer.SanitizeYear(startGradYear)}-{LogSanitizer.SanitizeYear(endGradYear)}", ex);
211211
}
212-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
212+
catch (Exception ex) when (ex is DbUpdateException or InvalidOperationException)
213213
{
214214
_logger.LogError(ex, "Error retrieving clinicians for grad year range {StartYear}-{EndYear}", LogSanitizer.SanitizeYear(startGradYear), LogSanitizer.SanitizeYear(endGradYear));
215215
throw new InvalidOperationException($"Failed to retrieve clinicians for grad year range {LogSanitizer.SanitizeYear(startGradYear)}-{LogSanitizer.SanitizeYear(endGradYear)}", ex);
@@ -240,7 +240,7 @@ public async Task<List<string>> GetAllMothraIdsAsync(CancellationToken cancellat
240240
_logger.LogInformation("Found {Count} unique MothraIds in Clinical Scheduler data", mothraIds.Count);
241241
return mothraIds;
242242
}
243-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
243+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
244244
{
245245
_logger.LogError(ex, "Error retrieving unique MothraIds");
246246
throw new InvalidOperationException("Failed to retrieve unique MothraIds from database", ex);
@@ -277,7 +277,7 @@ public async Task<List<ClinicianSummary>> GetAllActiveEmployeeAffiliatesAsync(Ca
277277
_logger.LogDebug("Found {Count} active employee affiliates from AAUD", allAffiliates.Count);
278278
return allAffiliates;
279279
}
280-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
280+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
281281
{
282282
_logger.LogError(ex, "Error retrieving active employee affiliates from AAUD");
283283
throw new InvalidOperationException("Failed to retrieve active employee affiliates from AAUD database", ex);
@@ -325,7 +325,7 @@ public async Task<List<ClinicianSummary>> GetAllActiveEmployeeAffiliatesAsync(Ca
325325

326326
return clinician;
327327
}
328-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
328+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
329329
{
330330
_logger.LogError(ex, "Error retrieving clinician data for MothraId: {MothraId} from AAUD", LogSanitizer.SanitizeId(mothraId));
331331
throw new InvalidOperationException($"Failed to retrieve clinician data for MothraId {LogSanitizer.SanitizeId(mothraId)} from AAUD", ex);

web/Areas/ClinicalScheduler/Services/RotationService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<List<RotationDto>> GetRotationsAsync(CancellationToken cancell
4646
rotations.Count);
4747
return rotations.Select(r => r.ToDto()).ToList();
4848
}
49-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
49+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
5050
{
5151
_logger.LogError(ex, "Error retrieving rotations from Clinical Scheduler");
5252
throw new InvalidOperationException("Failed to retrieve rotations from Clinical Scheduler database", ex);
@@ -83,7 +83,7 @@ public async Task<List<RotationDto>> GetRotationsAsync(CancellationToken cancell
8383

8484
return rotation?.ToDto();
8585
}
86-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
86+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
8787
{
8888
_logger.LogError(ex, "Error retrieving rotation by ID: {RotationId}", rotationId);
8989
throw new InvalidOperationException($"Failed to retrieve rotation with ID {rotationId}", ex);
@@ -125,7 +125,7 @@ public async Task<List<Rotation>> GetRotationsByCourseAsync(string courseNumber,
125125

126126
return rotations;
127127
}
128-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
128+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
129129
{
130130
_logger.LogError(ex, "Error retrieving rotations by course - CourseNumber: {CourseNumber}, SubjectCode: {SubjectCode}",
131131
courseNumber, subjectCode);
@@ -155,7 +155,7 @@ public async Task<List<RotationDto>> GetRotationsByServiceAsync(int serviceId, C
155155
_logger.LogInformation("Retrieved {Count} rotations for service ID: {ServiceId}", rotations.Count, serviceId);
156156
return rotations.Select(r => r.ToDto()).ToList();
157157
}
158-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
158+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
159159
{
160160
_logger.LogError(ex, "Error retrieving rotations by service ID: {ServiceId}", serviceId);
161161
throw new InvalidOperationException($"Failed to retrieve rotations for service ID {serviceId}", ex);
@@ -181,7 +181,7 @@ public async Task<List<ServiceDto>> GetServicesAsync(CancellationToken cancellat
181181
_logger.LogInformation("Retrieved {Count} services from Clinical Scheduler", services.Count);
182182
return services.Select(s => s.ToDto()).ToList();
183183
}
184-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
184+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
185185
{
186186
_logger.LogError(ex, "Error retrieving services from Clinical Scheduler");
187187
throw new InvalidOperationException("Failed to retrieve services from Clinical Scheduler database", ex);
@@ -216,7 +216,7 @@ public async Task<List<ServiceDto>> GetServicesAsync(CancellationToken cancellat
216216

217217
return service?.ToDto();
218218
}
219-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
219+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
220220
{
221221
_logger.LogError(ex, "Error retrieving service by ID: {ServiceId}", serviceId);
222222
throw new InvalidOperationException($"Failed to retrieve service with ID {serviceId}", ex);
@@ -266,7 +266,7 @@ public async Task<List<InstructorSchedule>> GetInstructorSchedulesByRotationAsyn
266266

267267
return schedules;
268268
}
269-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
269+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
270270
{
271271
_logger.LogError(ex, "Error retrieving instructor schedules for rotation ID: {RotationId}", rotationId);
272272
throw new InvalidOperationException($"Failed to retrieve instructor schedules for rotation ID {rotationId}", ex);

web/Areas/ClinicalScheduler/Services/ScheduleAuditService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public async Task<List<ScheduleAudit>> GetInstructorScheduleAuditHistoryAsync(
115115
.OrderByDescending(a => a.TimeStamp)
116116
.ToListAsync(cancellationToken);
117117
}
118-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
118+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
119119
{
120120
_logger.LogError(ex, "Error retrieving audit history for instructor schedule {ScheduleId}", instructorScheduleId);
121121
throw new InvalidOperationException($"Failed to retrieve audit history for instructor schedule {instructorScheduleId}. Please try again or contact support if the problem persists.", ex);
@@ -135,7 +135,7 @@ public async Task<List<ScheduleAudit>> GetRotationWeekAuditHistoryAsync(
135135
.OrderByDescending(a => a.TimeStamp)
136136
.ToListAsync(cancellationToken);
137137
}
138-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
138+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
139139
{
140140
_logger.LogError(ex, "Error retrieving audit history for rotation {RotationId}, week {WeekId}", rotationId, weekId);
141141
throw new InvalidOperationException($"Failed to retrieve audit history for rotation {rotationId}, week {weekId}. Please try again or contact support if the problem persists.", ex);
@@ -180,7 +180,7 @@ private async Task<ScheduleAudit> CreateAuditEntryAsync(
180180

181181
return auditEntry;
182182
}
183-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
183+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
184184
{
185185
_logger.LogError(ex, "Error creating audit entry for action {Action}, {MothraId} on rotation {RotationId}, week {WeekId}",
186186
action, LogSanitizer.SanitizeId(mothraId), rotationId, weekId);

web/Areas/ClinicalScheduler/Services/ScheduleEditService.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ await _auditService.LogPrimaryEvaluatorSetAsync(
241241
// Re-throw InvalidOperationException without wrapping (includes "already scheduled" messages)
242242
throw;
243243
}
244-
catch (Exception saveEx) when (saveEx is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
244+
catch (Exception saveEx) when (saveEx is DbUpdateException or SqlException)
245245
{
246246
_logger.LogError(saveEx, "Database save failed for MothraId='{MothraId}', RotationId={RotationId}, WeekIds=[{WeekIds}]",
247247
LogSanitizer.SanitizeId(mothraId), rotationId, string.Join(",", weekIds));
@@ -359,7 +359,7 @@ await _auditService.LogInstructorRemovedAsync(
359359
// Re-throw InvalidOperationException without wrapping (includes "Cannot remove primary evaluator" message)
360360
throw;
361361
}
362-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
362+
catch (Exception ex) when (ex is DbUpdateException or SqlException)
363363
{
364364
_logger.LogError(ex, "Error removing instructor schedule {ScheduleId}", instructorScheduleId);
365365
throw new InvalidOperationException($"Failed to remove instructor schedule. Please try again or contact support if the problem persists.", ex);
@@ -470,7 +470,7 @@ await _auditService.LogPrimaryEvaluatorSetAsync(
470470

471471
return (true, previousPrimaryName);
472472
}
473-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
473+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
474474
{
475475
_logger.LogError(ex, "Error setting primary evaluator for instructor schedule {ScheduleId} to {IsPrimary}", instructorScheduleId, isPrimary);
476476
throw new InvalidOperationException($"Failed to update primary evaluator status. Please try again or contact support if the problem persists.", ex);
@@ -495,7 +495,7 @@ public async Task<bool> CanRemoveInstructorAsync(
495495
// All instructors can now be removed, including primary evaluators
496496
return true;
497497
}
498-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
498+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
499499
{
500500
_logger.LogError(ex, "Error checking if instructor schedule {ScheduleId} can be removed", instructorScheduleId);
501501
return false;
@@ -537,7 +537,7 @@ public async Task<List<InstructorSchedule>> GetOtherRotationSchedulesAsync(
537537

538538
return await query.ToListAsync(cancellationToken);
539539
}
540-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
540+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
541541
{
542542
_logger.LogError(ex, "Error checking other rotation schedules for {MothraId} on weeks {WeekIds} for grad year {GradYear}",
543543
LogSanitizer.SanitizeId(mothraId), string.Join(",", weekIds), LogSanitizer.SanitizeYear(gradYear));
@@ -565,7 +565,7 @@ public async Task<List<InstructorSchedule>> GetScheduledInstructorsAsync(
565565
.Where(s => s.RotationId == rotationId && weekIds.Contains(s.WeekId))
566566
.ToListAsync(cancellationToken);
567567
}
568-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
568+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
569569
{
570570
_logger.LogError(ex, "Error getting scheduled instructors for rotation {RotationId} on weeks {WeekIds}", rotationId, string.Join(",", weekIds));
571571
throw new InvalidOperationException($"Failed to retrieve scheduled instructors. Please try again or contact support if the problem persists.", ex);
@@ -668,7 +668,7 @@ private async Task SendPrimaryEvaluatorRemovedNotificationAsync(InstructorSchedu
668668
}
669669
}
670670
}
671-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
671+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
672672
{
673673
_logger.LogWarning(ex, "Could not retrieve instructor name for {MothraId} in email notification", LogSanitizer.SanitizeId(schedule.MothraId));
674674
}
@@ -701,7 +701,7 @@ await _context.Entry(schedule)
701701
weekNumber = weekGradYear.WeekNum.ToString();
702702
}
703703
}
704-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
704+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
705705
{
706706
_logger.LogWarning(ex, "Could not retrieve week number for {WeekId} in email notification", schedule.WeekId);
707707
}
@@ -726,7 +726,7 @@ await _context.Entry(schedule)
726726
: "";
727727
}
728728
}
729-
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException or OperationCanceledException)
729+
catch (Exception ex) when (ex is DbUpdateException or SqlException or InvalidOperationException)
730730
{
731731
_logger.LogWarning(ex, "Could not retrieve modifier information for {MothraId} in email notification", modifiedByMothraId);
732732
}

0 commit comments

Comments
 (0)