diff --git a/android/fastlane/metadata/android/en-US/changelogs/139.txt b/android/fastlane/metadata/android/en-US/changelogs/139.txt new file mode 100644 index 0000000000..4c32282e1d --- /dev/null +++ b/android/fastlane/metadata/android/en-US/changelogs/139.txt @@ -0,0 +1 @@ +- Improves handling of a few common errors \ No newline at end of file diff --git a/lib/blocs/drive_detail/drive_detail_cubit.dart b/lib/blocs/drive_detail/drive_detail_cubit.dart index 33c9368528..137ce3a932 100644 --- a/lib/blocs/drive_detail/drive_detail_cubit.dart +++ b/lib/blocs/drive_detail/drive_detail_cubit.dart @@ -7,6 +7,7 @@ import 'package:ardrive/core/activity_tracker.dart'; import 'package:ardrive/models/models.dart'; import 'package:ardrive/pages/pages.dart'; import 'package:ardrive/services/services.dart'; +import 'package:ardrive/sync/domain/cubit/sync_cubit.dart'; import 'package:ardrive/utils/constants.dart'; import 'package:ardrive/utils/local_key_value_store.dart'; import 'package:ardrive/utils/logger.dart'; @@ -30,6 +31,7 @@ class DriveDetailCubit extends Cubit { final ArDriveAuth _auth; final ActivityTracker _activityTracker; final BreadcrumbBuilder _breadcrumbBuilder; + final SyncCubit _syncCubit; StreamSubscription? _folderSubscription; final _defaultAvailableRowsPerPage = [25, 50, 75, 100]; @@ -54,12 +56,14 @@ class DriveDetailCubit extends Cubit { required ActivityTracker activityTracker, required ArDriveAuth auth, required BreadcrumbBuilder breadcrumbBuilder, + required SyncCubit syncCubit, }) : _profileCubit = profileCubit, _activityTracker = activityTracker, _driveDao = driveDao, _auth = auth, _configService = configService, _breadcrumbBuilder = breadcrumbBuilder, + _syncCubit = syncCubit, super(DriveDetailLoadInProgress()) { if (driveId.isEmpty) { return; @@ -97,6 +101,9 @@ class DriveDetailCubit extends Cubit { DriveOrder contentOrderBy = DriveOrder.name, OrderingMode contentOrderingMode = OrderingMode.asc, }) async { + /// always wait for the current sync to finish before opening a new folder + await _syncCubit.waitCurrentSync(); + try { _selectedItem = null; _allImagesOfCurrentFolder = null; @@ -106,35 +113,6 @@ class DriveDetailCubit extends Cubit { emit(DriveDetailLoadInProgress()); await _folderSubscription?.cancel(); - // For attaching drives. If drive is not found, emit state to prompt drive attach - await _driveDao - .driveById(driveId: driveId) - .getSingleOrNull() - .then((value) async { - logger.d('Drive with id $driveId found'); - - if (value == null) { - logger.d('Drive with id $driveId not found'); - - emit(DriveDetailLoadNotFound()); - return; - } - - try { - await _driveDao - .folderById( - driveId: driveId, - folderId: folderId ?? value.rootFolderId, - ) - .getSingle(); - } catch (e) { - logger - .d('Folder with id ${folderId ?? value.rootFolderId} not found'); - - emit(DriveInitialLoading()); - return; - } - }); _folderSubscription = Rx.combineLatest3( @@ -259,6 +237,20 @@ class DriveDetailCubit extends Cubit { } catch (e, stacktrace) { logger.e('An error occured mouting the drive explorer', e, stacktrace); } + + _folderSubscription?.onError((e) { + if (e is FolderNotFoundInDriveException) { + emit(DriveInitialLoading()); + return; + } + + if (e is DriveNotFoundException) { + emit(DriveDetailLoadNotFound()); + return; + } + + logger.e('An error occured mouting the drive explorer', e); + }); } List parseEntitiesToDatatableItem({ diff --git a/lib/models/daos/drive_dao/drive_dao.dart b/lib/models/daos/drive_dao/drive_dao.dart index 2945b2c3f5..becb8f23bb 100644 --- a/lib/models/daos/drive_dao/drive_dao.dart +++ b/lib/models/daos/drive_dao/drive_dao.dart @@ -362,16 +362,21 @@ class DriveDao extends DatabaseAccessor with _$DriveDaoMixin { if (folderId == null) { return driveById(driveId: driveId).watchSingleOrNull().switchMap((drive) { if (drive == null) { - throw Exception('Drive with id $driveId not found'); + throw DriveNotFoundException(driveId); } return folderById(driveId: driveId, folderId: drive.rootFolderId) .watchSingleOrNull() .switchMap((folder) { - return watchFolderContents(driveId, - folderId: folder!.id, - orderBy: orderBy, - orderingMode: orderingMode); + if (folder == null) { + throw FolderNotFoundInDriveException(driveId, drive.rootFolderId); + } + return watchFolderContents( + driveId, + folderId: folder.id, + orderBy: orderBy, + orderingMode: orderingMode, + ); }); }); } @@ -656,3 +661,26 @@ class DriveDao extends DatabaseAccessor with _$DriveDaoMixin { }); } } + +class FolderNotFoundInDriveException implements Exception { + final String driveId; + final String folderId; + + FolderNotFoundInDriveException(this.driveId, this.folderId); + + @override + String toString() { + return 'Folder with id $folderId not found in drive with id $driveId'; + } +} + +class DriveNotFoundException implements Exception { + final String driveId; + + DriveNotFoundException(this.driveId); + + @override + String toString() { + return 'Drive with id $driveId not found'; + } +} diff --git a/lib/pages/app_router_delegate.dart b/lib/pages/app_router_delegate.dart index a903233cf1..41945aa575 100644 --- a/lib/pages/app_router_delegate.dart +++ b/lib/pages/app_router_delegate.dart @@ -202,6 +202,7 @@ class AppRouterDelegate extends RouterDelegate breadcrumbBuilder: BreadcrumbBuilder( context.read(), ), + syncCubit: context.read(), ), child: MultiBlocListener( listeners: [ diff --git a/pubspec.yaml b/pubspec.yaml index 4976c1bebd..2e5b1d4578 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Secure, permanent storage publish_to: 'none' -version: 2.49.2 +version: 2.49.3 environment: sdk: '>=3.2.0 <4.0.0'