Merge pull request #943 from pangeachat/sentry

don't call .floor() on level calculation if NaN or infinity, better e…
This commit is contained in:
ggurdin 2024-11-11 14:12:54 -05:00 committed by GitHub
commit dbafd05eab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 113 additions and 46 deletions

View file

@ -4493,5 +4493,6 @@
"enterLanguageLevel": "Please enter a language level",
"enterDiscussionTopic": "Please enter a discussion topic",
"selectBotChatMode": "Select chat mode",
"messageNotInTargetLang": "Message not in target language"
"messageNotInTargetLang": "Message not in target language",
"other": "Other"
}

View file

@ -1167,6 +1167,13 @@ class ChatController extends State<ChatPageWithRoom>
}
void sendAgainAction() {
// #Pangea
if (selectedEvents.isEmpty) {
ErrorHandler.logError(e: "No selected events in send again action");
clearSelectedEvents();
return;
}
// Pangea#
final event = selectedEvents.first;
if (event.status.isError) {
event.sendAgain();

View file

@ -96,43 +96,67 @@ class ChatInputRow extends StatelessWidget {
else
// Pangea#
controller.selectedEvents.length == 1
? controller.selectedEvents.first
.getDisplayEvent(controller.timeline!)
.status
.isSent
? SizedBox(
height: height,
child: TextButton(
onPressed: controller.replyAction,
child: Row(
children: <Widget>[
// #Pangea
// Text(L10n.of(context)!.reply),
// const Icon(Icons.keyboard_arrow_right),
const Icon(Symbols.reply),
const SizedBox(width: 6),
Text(L10n.of(context)!.reply),
// Pangea#
],
),
),
)
: SizedBox(
height: height,
child: TextButton(
onPressed: controller.sendAgainAction,
child: Row(
children: <Widget>[
Text(L10n.of(context)!.tryToSendAgain),
const SizedBox(width: 4),
const Icon(Icons.send_outlined, size: 16),
],
),
),
)
?
// #Pangea
// controller.selectedEvents.first
// .getDisplayEvent(controller.timeline!)
// .status
// .isSent
// ?
// Pangea#
SizedBox(
height: height,
child: TextButton(
onPressed: controller.replyAction,
child: Row(
children: <Widget>[
// #Pangea
// Text(L10n.of(context)!.reply),
// const Icon(Icons.keyboard_arrow_right),
const Icon(Symbols.reply),
const SizedBox(width: 6),
Text(L10n.of(context)!.reply),
// Pangea#
],
),
),
)
// #Pangea
// : SizedBox(
// height: height,
// child: TextButton(
// onPressed: controller.sendAgainAction,
// child: Row(
// children: <Widget>[
// Text(L10n.of(context)!.tryToSendAgain),
// const SizedBox(width: 4),
// const Icon(Icons.send_outlined, size: 16),
// ],
// ),
// ),
// )
// Pangea#
: const SizedBox.shrink(),
// #Pangea
PangeaReactionsPicker(controller),
if (controller.selectedEvents.length == 1 &&
!controller.selectedEvents.first
.getDisplayEvent(controller.timeline!)
.status
.isSent)
SizedBox(
height: height,
child: TextButton(
onPressed: controller.sendAgainAction,
child: Row(
children: <Widget>[
Text(L10n.of(context)!.tryToSendAgain),
const SizedBox(width: 4),
const Icon(Icons.send_outlined, size: 16),
],
),
),
),
// Pangea#
]
: <Widget>[

View file

@ -130,7 +130,7 @@ class RepresentationEvent {
data: {
'content': content.toJson(),
'event': _event?.toJson(),
'timestamp': timestamp,
'timestamp': timestamp.toIso8601String(),
'senderID': senderID,
},
);

View file

@ -4,6 +4,7 @@ import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart';
import 'package:fluffychat/pangea/models/analytics/constructs_model.dart';
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
/// A wrapper around a list of [OneConstructUse]s, used to simplify
/// the process of filtering / sorting / displaying the events.
@ -104,7 +105,23 @@ class ConstructListModel {
0,
(total, construct) => total + construct.points,
);
level = 1 + sqrt((1 + 8 * totalXP / 100) / 2).floor();
// Don't call .floor() if NaN or Infinity
// https://pangea-chat.sentry.io/issues/6052871310
final double levelCalculation = 1 + sqrt((1 + 8 * totalXP / 100) / 2);
if (!levelCalculation.isNaN && levelCalculation.isFinite) {
level = levelCalculation.floor();
} else {
level = 0;
ErrorHandler.logError(
e: "Calculated level in Nan or Infinity",
data: {
"totalXP": totalXP,
"prevXP": prevXP,
"level": levelCalculation,
},
);
}
}
ConstructUses? getConstructUses(ConstructIdentifier identifier) {

View file

@ -55,12 +55,17 @@ class AnalyticsPopupState extends State<AnalyticsPopup> {
selectedCategory = category;
});
String categoryCopy(category) =>
widget.type.getDisplayCopy(
category,
context,
) ??
category;
String categoryCopy(category) {
if (category.toLowerCase() == "other") {
return L10n.of(context)!.other;
}
return widget.type.getDisplayCopy(
category,
context,
) ??
category;
}
@override
Widget build(BuildContext context) {

View file

@ -7,6 +7,7 @@ import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_record_model.dart';
import 'package:fluffychat/pangea/utils/bot_style.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/widgets/chat/tts_controller.dart';
import 'package:fluffychat/pangea/widgets/practice_activity/practice_activity_card.dart';
import 'package:fluffychat/pangea/widgets/practice_activity/word_audio_button.dart';
@ -68,7 +69,16 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
);
if (currentRecordModel == null ||
currentRecordModel!.latestResponse == null) {
currentRecordModel?.latestResponse == null ||
widget.practiceCardController.currentActivity == null) {
ErrorHandler.logError(
e: "Missing necessary information to send analytics in multiple choice activity",
data: {
"currentRecordModel": currentRecordModel,
"latestResponse": currentRecordModel?.latestResponse,
"currentActivity": widget.practiceCardController.currentActivity,
},
);
debugger(when: kDebugMode);
return;
}

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:fluffychat/utils/error_reporter.dart';
import 'package:flutter/material.dart';
class FluffyChatErrorWidget extends StatefulWidget {
final FlutterErrorDetails details;
@ -21,6 +20,10 @@ class _FluffyChatErrorWidgetState extends State<FluffyChatErrorWidget> {
}
knownExceptions.add(widget.details.exception.toString());
WidgetsBinding.instance.addPostFrameCallback((_) {
// #Pangea
// related sentry issue: https://pangea-chat.sentry.io/issues/5970490357
if (!context.mounted) return;
// Pangea#
ErrorReporter(context, 'Error Widget').onErrorCallback(
widget.details.exception,
widget.details.stack,