Skip to content

Commit ad5275c

Browse files
authored
Merge pull request #240 from pangeachat/range-error-handling
better error handling for range errors in span cards
2 parents 6eb9f8c + c109092 commit ad5275c

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

lib/pangea/choreographer/controllers/igc_controller.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ class IgcController {
113113
),
114114
);
115115

116-
igcTextData!.matches[matchIndex].match = response.span;
116+
try {
117+
igcTextData!.matches[matchIndex].match = response.span;
118+
} catch (err, s) {
119+
ErrorHandler.logError(e: err, s: s);
120+
}
117121

118122
choreographer.setState();
119123
}

lib/pangea/models/representation_content_model.dart

-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import 'package:fluffychat/pangea/constants/language_keys.dart';
21
import 'package:fluffychat/pangea/models/speech_to_text_models.dart';
3-
import 'package:fluffychat/pangea/utils/error_handler.dart';
42
import 'package:matrix/matrix.dart';
5-
import 'package:sentry_flutter/sentry_flutter.dart';
63

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

5855
factory PangeaRepresentation.fromJson(Map<String, dynamic> json) {
59-
if (json[_langCodeKey] == LanguageKeys.unknownLanguage) {
60-
ErrorHandler.logError(
61-
e: Exception("Language code cannot be 'unk'"),
62-
s: StackTrace.current,
63-
data: {"rep_content": json},
64-
level: SentryLevel.warning,
65-
);
66-
}
6756
return PangeaRepresentation(
6857
langCode: json[_langCodeKey],
6958
text: json[_textKey],

lib/pangea/models/span_card_model.dart

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
22
import 'package:fluffychat/pangea/models/pangea_match_model.dart';
3+
import 'package:fluffychat/pangea/utils/error_handler.dart';
34

45
class SpanCardModel {
56
// IGCTextData igcTextData;
@@ -21,6 +22,18 @@ class SpanCardModel {
2122
required this.choreographer,
2223
});
2324

24-
PangeaMatch? get pangeaMatch =>
25-
choreographer.igc.igcTextData?.matches[matchIndex];
25+
PangeaMatch? get pangeaMatch {
26+
if (choreographer.igc.igcTextData == null) return null;
27+
if (matchIndex >= choreographer.igc.igcTextData!.matches.length) {
28+
ErrorHandler.logError(
29+
m: "matchIndex out of bounds in span card",
30+
data: {
31+
"matchIndex": matchIndex,
32+
"matchesLength": choreographer.igc.igcTextData?.matches.length,
33+
},
34+
);
35+
return null;
36+
}
37+
return choreographer.igc.igcTextData?.matches[matchIndex];
38+
}
2639
}

lib/pangea/widgets/igc/span_card.dart

+8-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ class SpanCardState extends State<SpanCard> {
5858
}
5959

6060
//get selected choice
61-
SpanChoice? get selectedChoice => selectedChoiceIndex != null &&
62-
widget.scm.pangeaMatch?.match.choices != null
63-
? widget.scm.pangeaMatch!.match.choices![selectedChoiceIndex!]
64-
: null;
61+
SpanChoice? get selectedChoice {
62+
if (selectedChoiceIndex == null ||
63+
widget.scm.pangeaMatch?.match.choices == null ||
64+
widget.scm.pangeaMatch!.match.choices!.length >= selectedChoiceIndex!) {
65+
return null;
66+
}
67+
return widget.scm.pangeaMatch?.match.choices?[selectedChoiceIndex!];
68+
}
6569

6670
Future<void> getSpanDetails() async {
6771
try {

0 commit comments

Comments
 (0)