From f7ed6d1a011713f7ba34c0d54d11d88ace6fe9b6 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Tue, 28 Sep 2021 17:05:33 +0800 Subject: [PATCH] Refactoring: replace tuple with actual class --- lib/bloc/list_album.dart | 12 ++++++------ lib/bloc/list_pending_shared_album.dart | 7 ++++--- lib/exception_event.dart | 9 +++++++++ lib/use_case/list_album.dart | 10 +++++----- lib/use_case/list_pending_shared_album.dart | 10 +++++----- 5 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 lib/exception_event.dart diff --git a/lib/bloc/list_album.dart b/lib/bloc/list_album.dart index 2444ee81..b5d3afd7 100644 --- a/lib/bloc/list_album.dart +++ b/lib/bloc/list_album.dart @@ -8,11 +8,11 @@ import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/entity/share/data_source.dart'; import 'package:nc_photos/event/event.dart'; import 'package:nc_photos/exception.dart'; +import 'package:nc_photos/exception_event.dart'; import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util; import 'package:nc_photos/string_extension.dart'; import 'package:nc_photos/throttler.dart'; import 'package:nc_photos/use_case/list_album.dart'; -import 'package:tuple/tuple.dart'; class ListAlbumBlocItem { ListAlbumBlocItem(this.album, this.isSharedByMe, this.isSharedToMe); @@ -232,15 +232,15 @@ class ListAlbumBloc extends Bloc { final errors = []; await for (final result in ListAlbum( FileRepo(fileDataSource), AlbumRepo(albumDataSrc))(ev.account)) { - if (result is Tuple2) { - if (result.item1 is CacheNotFoundException) { + if (result is ExceptionEvent) { + if (result.error is CacheNotFoundException) { _log.info( - "[_queryWithAlbumDataSource] Cache not found", result.item1); + "[_queryWithAlbumDataSource] Cache not found", result.error); } else { _log.shout("[_queryWithAlbumDataSource] Exception while ListAlbum", - result.item1, result.item2); + result.error, result.stackTrace); } - errors.add(result.item1); + errors.add(result.error); } else if (result is Album) { albums.add(result); } diff --git a/lib/bloc/list_pending_shared_album.dart b/lib/bloc/list_pending_shared_album.dart index 3ab092ff..fa8a4bdc 100644 --- a/lib/bloc/list_pending_shared_album.dart +++ b/lib/bloc/list_pending_shared_album.dart @@ -5,6 +5,7 @@ import 'package:nc_photos/entity/album.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file/data_source.dart'; import 'package:nc_photos/event/event.dart'; +import 'package:nc_photos/exception_event.dart'; import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util; import 'package:nc_photos/use_case/list_pending_shared_album.dart'; import 'package:tuple/tuple.dart'; @@ -138,10 +139,10 @@ class ListPendingSharedAlbumBloc extends Bloc< final errors = []; await for (final result in ListPendingSharedAlbum(fileRepo, albumRepo)(ev.account)) { - if (result is Tuple2) { + if (result is ExceptionEvent) { _log.severe("[_onEventQuery] Exception while ListPendingSharedAlbum", - result.item1, result.item2); - errors.add(result.item1); + result.error, result.stackTrace); + errors.add(result.error); } else if (result is Album) { albums.add(result); } diff --git a/lib/exception_event.dart b/lib/exception_event.dart new file mode 100644 index 00000000..ad25b2ef --- /dev/null +++ b/lib/exception_event.dart @@ -0,0 +1,9 @@ +class ExceptionEvent { + const ExceptionEvent( + this.error, [ + this.stackTrace, + ]); + + final dynamic error; + final StackTrace? stackTrace; +} diff --git a/lib/use_case/list_album.dart b/lib/use_case/list_album.dart index ae6dfb55..c7950165 100644 --- a/lib/use_case/list_album.dart +++ b/lib/use_case/list_album.dart @@ -3,11 +3,11 @@ import 'package:nc_photos/account.dart'; import 'package:nc_photos/entity/album.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/exception.dart'; +import 'package:nc_photos/exception_event.dart'; import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util; import 'package:nc_photos/use_case/compat/v15.dart'; import 'package:nc_photos/use_case/compat/v25.dart'; import 'package:nc_photos/use_case/ls.dart'; -import 'package:tuple/tuple.dart'; class ListAlbum { ListAlbum(this.fileRepo, this.albumRepo); @@ -38,12 +38,12 @@ class ListAlbum { File( path: remote_storage_util.getRemoteAlbumsDir(account), )); - } catch (e, stacktrace) { + } catch (e, stackTrace) { if (e is ApiException && e.response.statusCode == 404) { // no albums return; } - yield Tuple2(e, stacktrace); + yield ExceptionEvent(e, stackTrace); return; } final albumFiles = @@ -56,8 +56,8 @@ class ListAlbum { } albumFiles[i] = f; yield await albumRepo.get(account, f); - } catch (e, stacktrace) { - yield Tuple2(e, stacktrace); + } catch (e, stackTrace) { + yield ExceptionEvent(e, stackTrace); } } try { diff --git a/lib/use_case/list_pending_shared_album.dart b/lib/use_case/list_pending_shared_album.dart index 187eb8db..c8a3d2a8 100644 --- a/lib/use_case/list_pending_shared_album.dart +++ b/lib/use_case/list_pending_shared_album.dart @@ -3,9 +3,9 @@ import 'package:nc_photos/account.dart'; import 'package:nc_photos/entity/album.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/exception.dart'; +import 'package:nc_photos/exception_event.dart'; import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util; import 'package:nc_photos/use_case/ls.dart'; -import 'package:tuple/tuple.dart'; class ListPendingSharedAlbum { ListPendingSharedAlbum(this.fileRepo, this.albumRepo); @@ -23,12 +23,12 @@ class ListPendingSharedAlbum { File( path: remote_storage_util.getRemotePendingSharedAlbumsDir(account), )); - } catch (e, stacktrace) { + } catch (e, stackTrace) { if (e is ApiException && e.response.statusCode == 404) { // no albums return; } - yield Tuple2(e, stacktrace); + yield ExceptionEvent(e, stackTrace); return; } final albumFiles = @@ -36,8 +36,8 @@ class ListPendingSharedAlbum { for (final f in albumFiles) { try { yield await albumRepo.get(account, f); - } catch (e, stacktrace) { - yield Tuple2(e, stacktrace); + } catch (e, stackTrace) { + yield ExceptionEvent(e, stackTrace); } } try {