Make error field mandatory

This commit is contained in:
Neeraj Gupta 2023-11-30 10:49:35 +05:30
parent 6780a3409c
commit 1ec2b14df2
34 changed files with 100 additions and 75 deletions

View file

@ -222,7 +222,7 @@ extension SectionTypeExtensions on SectionType {
},
);
if (result is Exception) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: result);
}
};
default:

View file

@ -196,7 +196,7 @@ class BillingService {
);
} catch (e) {
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
await dialog.hide();
}

View file

@ -154,7 +154,7 @@ extension HiddenService on CollectionsService {
} catch (e, s) {
_logger.severe("Could not hide", e, s);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return false;
} finally {
await dialog.hide();

View file

@ -113,8 +113,9 @@ class UserService {
),
);
return;
} else {
throw Exception("send-ott action failed, non-200");
}
unawaited(showGenericErrorDialog(context: context));
} on DioError catch (e) {
await dialog.hide();
_logger.info(e);
@ -261,7 +262,7 @@ class UserService {
//to close and only then to show the error dialog.
Future.delayed(
const Duration(milliseconds: 150),
() => showGenericErrorDialog(context: context),
() => showGenericErrorDialog(context: context, error: null),
);
}
}
@ -281,7 +282,7 @@ class UserService {
}
} catch (e) {
_logger.severe(e);
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: e);
return null;
}
}
@ -958,7 +959,7 @@ class UserService {
try {
recoveryKey = await getOrCreateRecoveryKey(context);
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return false;
}
final dialog = createProgressDialog(context, S.of(context).verifying);

View file

@ -262,7 +262,7 @@ class _DeleteAccountPageState extends State<DeleteAccountPage> {
isDismissible: false,
);
if (choice!.action == ButtonAction.error) {
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: choice.exception);
}
}
@ -289,7 +289,7 @@ class _DeleteAccountPageState extends State<DeleteAccountPage> {
showShortToast(context, S.of(context).yourAccountHasBeenDeleted);
} catch (e, s) {
Logger("DeleteAccount").severe("failed to delete", e, s);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}

View file

@ -404,7 +404,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
} catch (e, s) {
_logger.severe(e, s);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}
@ -456,7 +456,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
} catch (e, s) {
_logger.severe(e, s);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}
@ -481,7 +481,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
S.of(context).sorryWeCouldNotGenerateSecureKeysOnThisDevicennplease,
);
} else {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}
}

View file

@ -51,7 +51,7 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
"Please check your internet connection and try again.",
);
} else {
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: e);
}
return;
}
@ -109,7 +109,7 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {
),
);
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return;
}
}

View file

@ -73,7 +73,7 @@ extension CollectionFileActions on CollectionActions {
);
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
showGenericErrorDialog(context: bContext);
showGenericErrorDialog(context: bContext, error: actionResult.exception);
} else {
selectedFiles.clearAll();
}
@ -187,7 +187,7 @@ extension CollectionFileActions on CollectionActions {
} catch (e, s) {
logger.severe("Failed to add to album", e, s);
await dialog?.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
rethrow;
}
}

View file

@ -52,7 +52,7 @@ class CollectionActions {
_showUnSupportedAlert(context);
} else {
logger.severe("Failed to update shareUrl collection", e);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
return false;
}
@ -93,7 +93,7 @@ class CollectionActions {
);
if (actionResult?.action != null) {
if (actionResult!.action == ButtonAction.error) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: actionResult.exception);
}
return actionResult.action == ButtonAction.first;
} else {
@ -142,7 +142,7 @@ class CollectionActions {
return collection;
} catch (e, s) {
dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
logger.severe("Failing to create link for selected files", e, s);
}
return null;
@ -183,7 +183,7 @@ class CollectionActions {
);
if (actionResult?.action != null) {
if (actionResult!.action == ButtonAction.error) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: actionResult.exception);
}
return actionResult.action == ButtonAction.first;
}
@ -230,7 +230,7 @@ class CollectionActions {
} catch (e) {
await dialog?.hide();
logger.severe("Failed to get public key", e);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return false;
}
// getPublicKey can return null when no user is associated with given
@ -272,7 +272,7 @@ class CollectionActions {
_showUnSupportedAlert(context);
} else {
logger.severe("failed to share collection", e);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
return false;
}
@ -353,7 +353,7 @@ class CollectionActions {
);
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
showGenericErrorDialog(context: bContext);
showGenericErrorDialog(context: bContext, error: actionResult.exception);
return false;
}
if ((actionResult?.action != null) &&

View file

@ -125,7 +125,7 @@ Future<void> showSingleFileDeleteSheet(
);
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: actionResult.exception);
}
}

View file

@ -111,6 +111,7 @@ class AlbumVerticalListWidget extends StatelessWidget {
if (result is Exception) {
showGenericErrorDialog(
context: context,
error: result,
);
_logger.severe(
"Failed to name album",
@ -310,7 +311,7 @@ class AlbumVerticalListWidget extends StatelessWidget {
);
return true;
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return false;
}
}
@ -333,7 +334,7 @@ class AlbumVerticalListWidget extends StatelessWidget {
),
);
} else {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: result);
_logger.severe("Cannot share collections owned by others");
}
}
@ -352,7 +353,10 @@ class AlbumVerticalListWidget extends StatelessWidget {
),
);
} else {
showGenericErrorDialog(context: context);
showGenericErrorDialog(
context: context,
error: Exception("Can not share collection owned by others"),
);
_logger.severe("Cannot share collections owned by others");
}
return Future.value(true);
@ -409,7 +413,7 @@ class AlbumVerticalListWidget extends StatelessWidget {
} catch (e, s) {
_logger.severe("Could not move to album", e, s);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return false;
}
}
@ -438,7 +442,7 @@ class AlbumVerticalListWidget extends StatelessWidget {
} catch (e, s) {
_logger.severe("Could not move to album", e, s);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return false;
}
}

View file

@ -55,7 +55,7 @@ class NewAlbumIcon extends StatelessWidget {
},
);
if (result is Exception) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: result);
}
},
);

View file

@ -498,7 +498,7 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
} else if (exception != null) {
//This is to show the execution was unsuccessful if the dialog is manually
//closed before the execution completes.
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: exception);
}
}
}

View file

@ -36,7 +36,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
bool _showCounter = false;
bool _showStepIndicator = true;
PageController? _pageController;
bool _shouldDisableScroll = false;
final bool _shouldDisableScroll = false;
late int currentUserID;
final GlobalKey shareButtonKey = GlobalKey();

View file

@ -123,7 +123,7 @@ class ChildSubscriptionWidget extends StatelessWidget {
},
);
if (choice!.action == ButtonAction.error) {
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: choice.exception);
}
}
}

View file

@ -190,7 +190,10 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
} else {
// should never reach here
_logger.severe("unexpected status", uri.toString());
showGenericErrorDialog(context: context);
showGenericErrorDialog(
context: context,
error: Exception("expected payment status $paymentStatus"),
);
}
}

View file

@ -524,11 +524,14 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
final ProductDetailsResponse response =
await InAppPurchase.instance.queryProductDetails({productID});
if (response.notFoundIDs.isNotEmpty) {
_logger.severe(
"Could not find products: " + response.notFoundIDs.toString(),
);
final errMsg = "Could not find products: " +
response.notFoundIDs.toString();
_logger.severe(errMsg);
await _dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(
context: context,
error: Exception(errMsg),
);
return;
}
final isCrossGradingOnAndroid = Platform.isAndroid &&

View file

@ -337,7 +337,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
).then((value) => onWebPaymentGoBack);
} catch (e) {
await _dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
await _dialog.hide();
}

View file

@ -232,7 +232,7 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {
} catch (e, s) {
_logger.severe("Failed to updated backup folder", e, s);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}

View file

@ -94,7 +94,7 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
try {
status = await SyncService.instance.getBackupStatus();
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return;
}
@ -128,7 +128,7 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
duplicates =
await DeduplicationService.instance.getDuplicateFiles();
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return;
}

View file

@ -89,7 +89,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
try {
recoveryKey = await _getOrCreateRecoveryKey(context);
} catch (e) {
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: e);
return;
}
unawaited(
@ -260,14 +260,22 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
await UserService.instance.getOrCreateRecoveryKey(context),
);
}
Future<void> updateEmailMFA(bool isEnabled) async {
try {
final UserDetails details = await UserService.instance.getUserDetailsV2(memoryCount: false);
if((details.profileData?.canDisableEmailMFA ?? false) == false) {
await routeToPage(context, RequestPasswordVerificationPage(onPasswordVerified: (Uint8List keyEncryptionKey) async {
final Uint8List loginKey = await CryptoUtil.deriveLoginKey(keyEncryptionKey);
await UserService.instance.registerOrUpdateSrp(loginKey);
},),);
final UserDetails details =
await UserService.instance.getUserDetailsV2(memoryCount: false);
if ((details.profileData?.canDisableEmailMFA ?? false) == false) {
await routeToPage(
context,
RequestPasswordVerificationPage(
onPasswordVerified: (Uint8List keyEncryptionKey) async {
final Uint8List loginKey =
await CryptoUtil.deriveLoginKey(keyEncryptionKey);
await UserService.instance.registerOrUpdateSrp(loginKey);
},
),
);
}
await UserService.instance.updateEmailMFA(isEnabled);
} catch (e) {

View file

@ -132,7 +132,7 @@ class _ManageIndividualParticipantState
CollectionParticipantRole.viewer,
);
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
if (isConvertToViewSuccess && mounted) {
// reset value

View file

@ -347,7 +347,7 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
}
} catch (e) {
await dialog?.hide();
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: e);
rethrow;
}
}

View file

@ -137,7 +137,7 @@ class _ItemsWidgetState extends State<ItemsWidget> {
try {
await CollectionsService.instance.updateShareUrl(widget.collection, prop);
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
rethrow;
}
}

View file

@ -180,7 +180,7 @@ class _ItemsWidgetState extends State<ItemsWidget> {
try {
await CollectionsService.instance.updateShareUrl(widget.collection, prop);
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
rethrow;
}
}

View file

@ -288,7 +288,7 @@ class FileAppBarState extends State<FileAppBar> {
}
} catch (e, s) {
_logger.severe("failed to update file visibility", e, s);
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: e);
}
}
@ -371,7 +371,7 @@ class FileAppBarState extends State<FileAppBar> {
} catch (e) {
_logger.warning("Failed to save file", e);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
} finally {
PhotoManager.startChangeNotify();
LocalSyncService.instance.checkAndSync().ignore();
@ -432,7 +432,7 @@ class FileAppBarState extends State<FileAppBar> {
} catch (e) {
dialog.hide();
_logger.severe("Failed to use as", e);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}
}

View file

@ -31,7 +31,7 @@ class EmptyAlbumState extends StatelessWidget {
try {
await showAddPhotosSheet(context, c);
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
},
),

View file

@ -172,7 +172,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
},
);
if (result is Exception) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: result);
}
}
@ -204,7 +204,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
if (actionResult?.action != null && mounted) {
if (actionResult!.action == ButtonAction.error) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: actionResult.exception);
} else if (actionResult.action == ButtonAction.first) {
Navigator.of(context).pop();
}
@ -224,7 +224,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
.getBackupStatus(pathID: widget.deviceCollection!.id);
} catch (e) {
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
return;
}
@ -664,7 +664,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
} catch (e, s) {
_logger.severe("failed to trash collection", e, s);
await dialog.hide();
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
} else {
final bool result = await collectionActions.deleteCollectionSheet(
@ -691,7 +691,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
} catch (e, s) {
_logger.severe("failed to trash collection", e, s);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}
@ -726,7 +726,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
} catch (e, s) {
_logger.severe(e, s);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}
@ -736,7 +736,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
await showAddPhotosSheet(bContext, collection!);
} catch (e, s) {
_logger.severe(e, s);
showGenericErrorDialog(context: bContext);
showGenericErrorDialog(context: bContext, error: e);
}
}

View file

@ -118,7 +118,7 @@ class LocationScreenPopUpMenu extends StatelessWidget {
);
Navigator.of(context).pop();
} catch (e) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
}
}
},

View file

@ -200,7 +200,7 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
alignMessage: Alignment.centerRight,
);
if (result is Exception) {
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: result);
_logger.severe(
"Failed to create custom radius",
result,

View file

@ -102,7 +102,7 @@ Future<void> deleteFilesFromEverywhere(
await FilesDB.instance.deleteMultipleUploadedFiles(fileIDs);
} catch (e) {
_logger.severe(e);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
rethrow;
}
for (final collectionID in updatedCollectionIDs) {
@ -163,7 +163,7 @@ Future<void> deleteFilesFromRemoteOnly(
await FilesDB.instance.deleteMultipleUploadedFiles(uploadedFileIDs);
} catch (e, s) {
_logger.severe("Failed to delete files from remote", e, s);
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
rethrow;
}
for (final collectionID in updatedCollectionIDs) {
@ -279,7 +279,10 @@ Future<bool> deleteFromTrash(BuildContext context, List<EnteFile> files) async {
actionResult!.action == ButtonAction.cancel) {
return didDeletionStart ? true : false;
} else if (actionResult.action == ButtonAction.error) {
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
);
return false;
} else {
return true;
@ -306,7 +309,10 @@ Future<bool> emptyTrash(BuildContext context) async {
actionResult!.action == ButtonAction.cancel) {
return false;
} else if (actionResult.action == ButtonAction.error) {
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(
context: context,
error: actionResult.exception,
);
return false;
} else {
return true;
@ -555,7 +561,7 @@ Future<void> showDeleteSheet(
showShortToast(context, S.of(context).movedToTrash);
},
onError: (e, s) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: e);
},
);
},
@ -620,7 +626,7 @@ Future<void> showDeleteSheet(
);
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: actionResult.exception);
} else {
selectedFiles.clearAll();
}

View file

@ -121,7 +121,7 @@ String parseErrorForUI(
Future<ButtonResult?> showGenericErrorDialog({
required BuildContext context,
bool isDismissible = true,
Object? error,
required Object? error,
}) async {
final errorBody = parseErrorForUI(
context,

View file

@ -218,7 +218,7 @@ Future<void> editFilename(
);
if (result is Exception) {
_logger.severe("Failed to rename file");
showGenericErrorDialog(context: context);
showGenericErrorDialog(context: context, error: result);
}
}

View file

@ -74,7 +74,7 @@ Future<void> share(
s,
);
await dialog.hide();
await showGenericErrorDialog(context: context);
await showGenericErrorDialog(context: context, error: e);
}
}