Skip to content

Commit

Permalink
Merge pull request #2068 from bitfriend/issue198_cleanup-periodically
Browse files Browse the repository at this point in the history
Add severe log for all EasyLoading.showError
  • Loading branch information
gnunicorn authored Aug 16, 2024
2 parents 30090f9 + 3d5b554 commit dd09681
Show file tree
Hide file tree
Showing 108 changed files with 821 additions and 541 deletions.
6 changes: 5 additions & 1 deletion app/lib/common/actions/close_room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::common::close');
final _log = Logger('a3::common::close_room');

Future<bool> openCloseRoomDialog({
required BuildContext context,
Expand Down Expand Up @@ -227,6 +227,10 @@ class _CloseRoomConfirmationState
Navigator.pop(context, true);
} catch (error, stack) {
_log.severe('Failure in closing room', error, stack);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
L10n.of(context).closingRoomFailed(error),
duration: const Duration(seconds: 3),
Expand Down
7 changes: 4 additions & 3 deletions app/lib/common/actions/redact_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::common::redact');
final _log = Logger('a3::common::redact_content');

Future<bool> openRedactContentDialog(
BuildContext context, {
Expand Down Expand Up @@ -136,13 +136,14 @@ class _RedactContentWidget extends ConsumerWidget {
if (onSuccess != null) {
onSuccess!();
}
} catch (e) {
} catch (e, s) {
_log.severe('Failed to redact content', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
'${L10n.of(context).redactionFailed} $e',
L10n.of(context).redactionFailed(e),
duration: const Duration(seconds: 3),
);
}
Expand Down
6 changes: 4 additions & 2 deletions app/lib/common/actions/report_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::common::report');
final _log = Logger('a3::common::report_content');

final _ignoreUserProvider = StateProvider.autoDispose<bool>((ref) => false);

Expand Down Expand Up @@ -159,12 +159,14 @@ class _ReportContentWidget extends ConsumerWidget {
EasyLoading.showToast(L10n.of(context).reportSent);
Navigator.pop(context);
} else {
_log.severe('Failed to report content');
EasyLoading.showError(
L10n.of(context).reportSendingFailed,
duration: const Duration(seconds: 3),
);
}
} catch (e) {
} catch (e, s) {
_log.severe('Failed to report content', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
Expand Down
21 changes: 14 additions & 7 deletions app/lib/common/dialogs/deactivation_confirmation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::common::deactivate');

const deactivateConfirmBtn = Key('deactivate-account-confirm');
const deactivateCancelBtn = Key('deactivate-account-cancel');
Expand Down Expand Up @@ -110,24 +113,28 @@ Future<void> _onConfirm(
try {
final result = await sdk.deactivateAndDestroyCurrentClient(password);
if (!result) {
if (context.mounted) {
EasyLoading.showError(
L10n.of(context).deactivationAndRemovingFailed,
duration: const Duration(seconds: 3),
);
_log.severe('Failed to deactivate and remove this client');
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
L10n.of(context).deactivationAndRemovingFailed,
duration: const Duration(seconds: 3),
);
return;
}
EasyLoading.dismiss();
if (!context.mounted) return;
context.goNamed(Routes.main.name);
} catch (err) {
} catch (e, s) {
_log.severe('Failed to deactivate and remove this client', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
L10n.of(context).deactivatingFailed(err),
L10n.of(context).deactivatingFailed(e),
duration: const Duration(seconds: 3),
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/common/providers/common_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ final canRedactProvider = FutureProvider.autoDispose.family<bool, dynamic>(
((ref, arg) async {
try {
return await arg.canRedact();
} catch (error) {
_log.severe('Fetching canRedact failed for $arg', error);
} catch (e, s) {
_log.severe('Fetching canRedact failed for $arg', e, s);
return false;
}
}),
Expand Down
30 changes: 18 additions & 12 deletions app/lib/common/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: unnecessary_null_comparison

import 'dart:async';
import 'dart:convert';
import 'dart:math';
Expand Down Expand Up @@ -205,13 +203,19 @@ Future<void> shareTextToWhatsApp(
} else {
_log.warning('WhatsApp not available');
if (!context.mounted) return;
EasyLoading.showError(L10n.of(context).appUnavailable);
EasyLoading.showError(
L10n.of(context).appUnavailable,
duration: const Duration(seconds: 3),
);
}
}

Future<void> mailTo({required String toAddress, String? subject}) async {
final Uri emailLaunchUri =
Uri(scheme: 'mailto', path: toAddress, query: subject);
final emailLaunchUri = Uri(
scheme: 'mailto',
path: toAddress,
query: subject,
);
await launchUrl(emailLaunchUri);
}

Expand Down Expand Up @@ -260,14 +264,16 @@ Future<void> uploadAvatar(
if (file.path != null) await room.uploadAvatar(file.path!);
// close loading
EasyLoading.dismiss();
} catch (e, st) {
_log.severe('Failed to upload avatar', e, st);
if (context.mounted) {
EasyLoading.showError(
L10n.of(context).failedToUploadAvatar(e),
duration: const Duration(seconds: 3),
);
} catch (e, s) {
_log.severe('Failed to upload avatar', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
L10n.of(context).failedToUploadAvatar(e),
duration: const Duration(seconds: 3),
);
}
}

Expand Down
24 changes: 9 additions & 15 deletions app/lib/common/widgets/chat/convo_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import 'package:atlas_icons/atlas_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_matrix_html/flutter_html.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:logging/logging.dart';
import 'package:skeletonizer/skeletonizer.dart';

final _log = Logger('a3::common::chat::convo_card');

class ConvoCard extends ConsumerWidget {
final String roomId;

Expand Down Expand Up @@ -60,10 +63,7 @@ class ConvoCard extends ConsumerWidget {
);
}

Widget renderTrailing(
BuildContext context,
WidgetRef ref,
) {
Widget renderTrailing(BuildContext context, WidgetRef ref) {
final mutedStatus = ref.watch(roomIsMutedProvider(roomId));
return Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand Down Expand Up @@ -101,12 +101,10 @@ class ConvoCard extends ConsumerWidget {
);
}

Future<void> onUnmute(
BuildContext context,
WidgetRef ref,
) async {
Future<void> onUnmute(BuildContext context, WidgetRef ref) async {
final room = await ref.read(maybeRoomProvider(roomId).future);
if (room == null) {
_log.severe('Room not found: $roomId');
if (!context.mounted) return;
EasyLoading.showError(
L10n.of(context).roomNotFound,
Expand All @@ -129,9 +127,7 @@ class ConvoCard extends ConsumerWidget {
class _SubtitleWidget extends ConsumerWidget {
final String roomId;

const _SubtitleWidget({
required this.roomId,
});
const _SubtitleWidget({required this.roomId});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -424,9 +420,7 @@ class _SubtitleWidget extends ConsumerWidget {
class _TrailingWidget extends ConsumerWidget {
final String roomId;

const _TrailingWidget({
required this.roomId,
});
const _TrailingWidget({required this.roomId});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down
9 changes: 6 additions & 3 deletions app/lib/common/widgets/chat/edit_room_description_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ class _EditRoomDescriptionSheetState
EasyLoading.dismiss();
if (!context.mounted) return;
Navigator.pop(context);
} catch (e, st) {
_log.severe('Failed to edit chat description', e, st);
} catch (e, s) {
_log.severe('Failed to edit chat description', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(L10n.of(context).updateDescriptionFailed(e));
EasyLoading.showError(
L10n.of(context).updateDescriptionFailed(e),
duration: const Duration(seconds: 3),
);
}
}
}
6 changes: 3 additions & 3 deletions app/lib/common/widgets/visibility/visibility_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class VisibilityChip extends ConsumerWidget {
data: (visibility) {
return renderSpaceChip(context, visibility);
},
error: (error, st) {
_log.severe('Failed to load room visibility', error, st);
error: (e, s) {
_log.severe('Failed to load room visibility', e, s);
return Chip(
label: Text(L10n.of(context).loadingFailed(error)),
label: Text(L10n.of(context).loadingFailed(e)),
);
},
loading: () => renderLoading(),
Expand Down
44 changes: 29 additions & 15 deletions app/lib/features/activities/widgets/invitation_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ class InvitationCard extends ConsumerWidget {
final lang = L10n.of(context);
try {
await invitation.accept();
} catch (error) {
_log.severe('Failure accepting invite', error);
if (!context.mounted) return;
} catch (e, s) {
_log.severe('Failure accepting invite', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
lang.failedToAcceptInvite(error),
lang.failedToAcceptInvite(e),
duration: const Duration(seconds: 3),
);
return;
Expand All @@ -182,19 +185,25 @@ class InvitationCard extends ConsumerWidget {
try {
// timeout to wait for 10seconds to ensure the room is ready
await client.waitForRoom(roomId, 10);
} catch (error) {
_log.warning("Joining $roomId didn't return within 10 seconds");
} catch (e, s) {
_log.warning('Joining $roomId didn’t return within 10 seconds', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showToast(lang.joinedDelayed);
// do not forward in this case
return;
}
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showToast(lang.joined);
if (context.mounted) {
if (isSpace) {
goToSpace(context, invitation.room().roomIdStr());
} else {
goToChat(context, invitation.room().roomIdStr());
}
if (isSpace) {
goToSpace(context, roomId);
} else {
goToChat(context, roomId);
}
}

Expand All @@ -209,15 +218,20 @@ class InvitationCard extends ConsumerWidget {
if (res) {
EasyLoading.showToast(L10n.of(context).rejected);
} else {
_log.severe('Failed to reject invitation');
EasyLoading.showError(
L10n.of(context).failedToReject,
duration: const Duration(seconds: 3),
);
}
} catch (error) {
_log.severe('Failure reject invite', error);
} catch (e, s) {
_log.severe('Failure reject invite', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
L10n.of(context).failedToRejectInvite(error),
L10n.of(context).failedToRejectInvite(e),
duration: const Duration(seconds: 3),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter_gen/gen_l10n/l10n.dart';

import 'package:acter/common/models/types.dart';
import 'package:acter/features/home/providers/client_providers.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart'
show AttachmentDraft, AttachmentsManager;
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:mime/mime.dart';

final _log = Logger('a3::action::attachments');
final _log = Logger('a3::attachments::actions::handle_selected');

// if generic attachment, send via manager
Future<void> handleAttachmentSelected({
Expand Down Expand Up @@ -76,8 +77,8 @@ Future<void> handleAttachmentSelected({
_log.info('attachment sent: $res');
}
EasyLoading.dismiss();
} catch (e) {
_log.severe('Error sending attachments', e);
} catch (e, s) {
_log.severe('Failed to create attachments', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
Expand Down
Loading

0 comments on commit dd09681

Please sign in to comment.