fix: throw exception if no activities can be loaded in analytics practice session (#5799)

This commit is contained in:
ggurdin 2026-02-24 15:28:17 -05:00 committed by GitHub
parent a754d16fc3
commit fd319aa105
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View file

@ -313,6 +313,8 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
Future<void> skipActivity(MessageActivityRequest request) async {
// Record a 0 XP use so that activity isn't chosen again soon
_sessionController.skipActivity();
progress.value = _sessionController.progress;
await _analyticsController.addSkippedActivityAnalytics(
request.target,
_l2!.langCodeShort,

View file

@ -152,12 +152,18 @@ class PracticeSessionController {
Future Function(MessageActivityRequest) onSkip,
Future Function(MultipleChoicePracticeActivityModel) onFetch,
) async {
final session = this.session;
if (session == null) {
throw Exception("Called getNextActivity without loading session");
}
if (!session!.isComplete && _queue.isEmpty) {
return _initActivityData(onSkip, onFetch);
if (!session.isComplete && _queue.isEmpty) {
final initialActivity = await _initActivityData(onSkip, onFetch);
if (initialActivity == null && session.state.currentIndex == 0) {
// No activities were successfully loaded, and we haven't completed any yet, so throw an error
throw Exception("Failed to load any activities");
}
return initialActivity;
}
while (_queue.isNotEmpty) {
@ -171,6 +177,12 @@ class PracticeSessionController {
continue;
}
}
if (session.state.currentIndex == 0) {
// No activities were successfully loaded, and we haven't completed any yet, so throw an error
throw Exception("Failed to load any activities");
}
return null;
}
}