diff --git a/lib/pangea/choreographer/controllers/igc_controller.dart b/lib/pangea/choreographer/controllers/igc_controller.dart index f5e15a1e33..73694e257d 100644 --- a/lib/pangea/choreographer/controllers/igc_controller.dart +++ b/lib/pangea/choreographer/controllers/igc_controller.dart @@ -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(); } diff --git a/lib/pangea/models/representation_content_model.dart b/lib/pangea/models/representation_content_model.dart index c4ff52fe75..f49a465b4c 100644 --- a/lib/pangea/models/representation_content_model.dart +++ b/lib/pangea/models/representation_content_model.dart @@ -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] @@ -56,14 +53,6 @@ class PangeaRepresentation { }); factory PangeaRepresentation.fromJson(Map 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], diff --git a/lib/pangea/models/span_card_model.dart b/lib/pangea/models/span_card_model.dart index 8a252e67b1..f74a14332b 100644 --- a/lib/pangea/models/span_card_model.dart +++ b/lib/pangea/models/span_card_model.dart @@ -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; @@ -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]; + } } diff --git a/lib/pangea/widgets/igc/span_card.dart b/lib/pangea/widgets/igc/span_card.dart index 7185d726ce..9ef2f41227 100644 --- a/lib/pangea/widgets/igc/span_card.dart +++ b/lib/pangea/widgets/igc/span_card.dart @@ -58,10 +58,14 @@ class SpanCardState extends State { } //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 getSpanDetails() async { try {