Skip to content

Commit ee2d042

Browse files
fix(exams): add Sentry capture + better logging for AI grading errors
Grading errors were silently swallowed in try/catch. Now logs the grading result error and reports exceptions to Sentry with examId and submissionId context. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 39d527d commit ee2d042

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

app/[locale]/dashboard/student/courses/[courseId]/exams/[examId]/exam-taker.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,14 @@ export function ExamTaker({
139139
// Trigger AI grading
140140
try {
141141
const { gradeExamWithAI } = await import('@/app/actions/exam-grading')
142-
await gradeExamWithAI({
142+
const gradingResult = await gradeExamWithAI({
143143
examId,
144144
submissionId: submission.submission_id,
145145
answers,
146146
})
147+
if (!gradingResult.success) {
148+
console.error('AI grading returned error:', gradingResult.error)
149+
}
147150
} catch (gradingError) {
148151
console.error('AI grading failed (non-blocking):', gradingError)
149152
// Continue to results page even if AI grading fails

app/actions/exam-grading.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ Evaluate these free-text answers now:`
454454
}
455455
} catch (error) {
456456
console.error('Error grading exam:', error)
457+
// Report to Sentry for observability
458+
try {
459+
const Sentry = await import('@sentry/nextjs')
460+
Sentry.captureException(error, { extra: { examId: params.examId, submissionId: params.submissionId } })
461+
} catch {}
457462
return {
458463
success: false,
459464
error: error instanceof Error ? error.message : 'Failed to grade exam',

0 commit comments

Comments
 (0)