better error handling for range errors in span cards

pull/1183/head
ggurdin 1 year ago
parent 6eb9f8c9d2
commit c1090925d1

@ -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();
}

@ -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<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],

@ -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];
}
}

@ -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 {

Loading…
Cancel
Save