-
Notifications
You must be signed in to change notification settings - Fork 315
fix: Improve error handling in whisper_transcription_controller #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: Improve error handling in whisper_transcription_controller #694
Conversation
…r transcription - Changed print() to log() with proper error context - Added segment index to identify which segment failed - Captured stack trace for debugging - Added snackbar to notify users when transcription errors occur
|
🎉 Welcome @YadavAkhileshh!
We appreciate your contribution! 🚀 |
📝 WalkthroughWalkthroughThis PR refactors error handling in the whisper transcription controller by replacing a generic catch clause with comprehensive error handling that captures stack traces, provides segment index context, and displays user-visible error notifications via snackbar. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @lib/controllers/whisper_transcription_controller.dart:
- Around line 73-84: In the catch block inside the transcription loop (the code
that currently logs errors with log(...) and calls customSnackbar), stop calling
customSnackbar per-segment; instead, collect failed segment indices (e.g., push
i or i+1 into a local List<int> failedSegments) and continue logging as before;
after the loop that invokes segment processing (the scope around the try/catch
that uses i), check if failedSegments is not empty and then call customSnackbar
once with a concise summary message (e.g., count and optional small list or
range of failed segment numbers) to inform the user of aggregated failures; keep
the detailed log(...) calls untouched so stack traces remain available for
debugging.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/controllers/whisper_transcription_controller.dart
🔇 Additional comments (2)
lib/controllers/whisper_transcription_controller.dart (2)
8-9: LGTM! Necessary imports for enhanced error handling.The added imports support the new logging type enumeration and user notification functionality.
64-66: LGTM! Index-based iteration enables precise error reporting.The refactoring from an enhanced for-loop to an index-based loop correctly enables segment index reporting in error messages, which was a key objective of this PR.
| } catch (e, stackTrace) { | ||
| log( | ||
| 'Error converting transcription segment at index $i: ${e.toString()}', | ||
| error: e, | ||
| stackTrace: stackTrace, | ||
| ); | ||
| customSnackbar( | ||
| 'Transcription Error', | ||
| 'Failed to process segment ${i + 1}. Some content may be missing.', | ||
| LogType.error, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor to avoid spamming users with multiple snackbars.
The enhanced error handling correctly captures stack traces and logs detailed information, which addresses the PR objectives well. However, showing a snackbar for each failed segment creates a poor user experience if multiple segments fail during transcription.
For example, if 5 segments out of 100 fail, the user will see 5 separate snackbars in rapid succession.
Consider refactoring to collect failed segment indices during the loop and display a single summary snackbar after processing completes.
♻️ Proposed refactor to show one summary snackbar
String convertToLrc(List<WhisperTranscribeSegment?> transcriptionSegments) {
final StringBuffer lrcContent = StringBuffer();
lrcContent.writeln('[re:Resonate App - AOSSIE]');
lrcContent.writeln('[ve:v1.0.0]');
+ final List<int> failedIndices = [];
for (int i = 0; i < transcriptionSegments.length; i++) {
try {
final segment = transcriptionSegments[i];
// Parse the log line
final segmentString = _parseTranscriptionSegment(segment);
if (segmentString != null) {
// Convert to LRC format and add to content
lrcContent.writeln(segmentString);
}
} catch (e, stackTrace) {
log(
'Error converting transcription segment at index $i: ${e.toString()}',
error: e,
stackTrace: stackTrace,
);
- customSnackbar(
- 'Transcription Error',
- 'Failed to process segment ${i + 1}. Some content may be missing.',
- LogType.error,
- );
+ failedIndices.add(i);
}
}
+
+ if (failedIndices.isNotEmpty) {
+ final count = failedIndices.length;
+ final total = transcriptionSegments.length;
+ customSnackbar(
+ 'Transcription Warning',
+ 'Failed to process $count of $total segments. Some content may be missing.',
+ LogType.error,
+ );
+ }
return lrcContent.toString();
}Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In @lib/controllers/whisper_transcription_controller.dart around lines 73 - 84,
In the catch block inside the transcription loop (the code that currently logs
errors with log(...) and calls customSnackbar), stop calling customSnackbar
per-segment; instead, collect failed segment indices (e.g., push i or i+1 into a
local List<int> failedSegments) and continue logging as before; after the loop
that invokes segment processing (the scope around the try/catch that uses i),
check if failedSegments is not empty and then call customSnackbar once with a
concise summary message (e.g., count and optional small list or range of failed
segment numbers) to inform the user of aggregated failures; keep the detailed
log(...) calls untouched so stack traces remain available for debugging.
Description
Fixed the print() statement issue in whisper_transcription_controller.dart
Changes
Fixes
Fixes #680
Testing
Checked the code follows existing patterns in the project. The snackbar uses the same customSnackbar widget used elsewhere in the app.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.