Skip to content

Commit

Permalink
better error handling for range errors in span cards
Browse files Browse the repository at this point in the history
  • Loading branch information
ggurdin committed May 23, 2024
1 parent 6eb9f8c commit c109092
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
6 changes: 5 additions & 1 deletion lib/pangea/choreographer/controllers/igc_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ class IgcController {
),
);

igcTextData!.matches[matchIndex].match = response.span;
try {
igcTextData!.matches[matchIndex].match = response.span;
} catch (err, s) {
ErrorHandler.logError(e: err, s: s);
}

choreographer.setState();
}
Expand Down
11 changes: 0 additions & 11 deletions lib/pangea/models/representation_content_model.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'package:fluffychat/pangea/constants/language_keys.dart';
import 'package:fluffychat/pangea/models/speech_to_text_models.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:matrix/matrix.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

/// this class is contained within a [RepresentationEvent]
/// this event is the child of a [EventTypes.Message]
Expand Down Expand Up @@ -56,14 +53,6 @@ class PangeaRepresentation {
});

factory PangeaRepresentation.fromJson(Map<String, dynamic> json) {
if (json[_langCodeKey] == LanguageKeys.unknownLanguage) {
ErrorHandler.logError(
e: Exception("Language code cannot be 'unk'"),
s: StackTrace.current,
data: {"rep_content": json},
level: SentryLevel.warning,
);
}
return PangeaRepresentation(
langCode: json[_langCodeKey],
text: json[_textKey],
Expand Down
17 changes: 15 additions & 2 deletions lib/pangea/models/span_card_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
import 'package:fluffychat/pangea/models/pangea_match_model.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';

class SpanCardModel {
// IGCTextData igcTextData;
Expand All @@ -21,6 +22,18 @@ class SpanCardModel {
required this.choreographer,
});

PangeaMatch? get pangeaMatch =>
choreographer.igc.igcTextData?.matches[matchIndex];
PangeaMatch? get pangeaMatch {
if (choreographer.igc.igcTextData == null) return null;
if (matchIndex >= choreographer.igc.igcTextData!.matches.length) {
ErrorHandler.logError(
m: "matchIndex out of bounds in span card",
data: {
"matchIndex": matchIndex,
"matchesLength": choreographer.igc.igcTextData?.matches.length,
},
);
return null;
}
return choreographer.igc.igcTextData?.matches[matchIndex];
}
}
12 changes: 8 additions & 4 deletions lib/pangea/widgets/igc/span_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ class SpanCardState extends State<SpanCard> {
}

//get selected choice
SpanChoice? get selectedChoice => selectedChoiceIndex != null &&
widget.scm.pangeaMatch?.match.choices != null
? widget.scm.pangeaMatch!.match.choices![selectedChoiceIndex!]
: null;
SpanChoice? get selectedChoice {
if (selectedChoiceIndex == null ||
widget.scm.pangeaMatch?.match.choices == null ||
widget.scm.pangeaMatch!.match.choices!.length >= selectedChoiceIndex!) {
return null;
}
return widget.scm.pangeaMatch?.match.choices?[selectedChoiceIndex!];
}

Future<void> getSpanDetails() async {
try {
Expand Down

0 comments on commit c109092

Please sign in to comment.