Migrate to ExceptionEvent

This commit is contained in:
Ming Ming 2021-10-26 22:44:33 +08:00
parent 1fdf438956
commit ded9af9d18
5 changed files with 22 additions and 16 deletions

View file

@ -9,6 +9,7 @@ import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/throttler.dart';
import 'package:nc_photos/use_case/scan_dir.dart';
@ -304,8 +305,8 @@ class ScanDirBloc extends Bloc<ScanDirBlocEvent, ScanDirBlocState> {
for (final r in ev.roots) {
final dataStream = ScanDir(FileRepo(dataSrc))(ev.account, r);
await for (final d in dataStream) {
if (d is Exception || d is Error) {
throw d;
if (d is ExceptionEvent) {
throw d.error;
}
yield ScanDirBlocLoading(ev.account, getState().files + d);
}

View file

@ -6,6 +6,7 @@ import 'package:nc_photos/entity/album/item.dart';
import 'package:nc_photos/entity/album/provider.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/use_case/scan_dir.dart';
class PopulateAlbum {
@ -31,11 +32,12 @@ class PopulateAlbum {
for (final d in provider.dirs) {
final stream = ScanDir(FileRepo(FileCachedDataSource()))(account, d);
await for (final result in stream) {
if (result is Exception || result is Error) {
if (result is ExceptionEvent) {
_log.shout(
"[_populateDirAlbum] Failed while scanning dir" +
(shouldLogFileName ? ": $d" : ""),
result);
result.error,
result.stackTrace);
continue;
}
products.addAll((result as List).cast<File>().map((f) => AlbumFileItem(

View file

@ -3,6 +3,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/debug_util.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';
@ -26,18 +27,18 @@ class ScanDir {
.endsWith(remote_storage_util.getRemoteStorageDir(account)))) {
yield* this(account, i);
}
} on CacheNotFoundException catch (e) {
} on CacheNotFoundException catch (e, stackTrace) {
_log.info("[call] Cache not found");
yield e;
} catch (e, stacktrace) {
yield ExceptionEvent(e, stackTrace);
} catch (e, stackTrace) {
_log.shout(
"[call] Failed while listing dir" +
(shouldLogFileName ? ": ${root.path}" : ""),
e,
stacktrace);
stackTrace);
// for some reason exception thrown here can't be caught outside
// rethrow;
yield e;
yield ExceptionEvent(e, stackTrace);
}
}

View file

@ -1,6 +1,7 @@
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/use_case/scan_dir.dart';
class ScanMissingMetadata {
@ -10,11 +11,11 @@ class ScanMissingMetadata {
/// recursively
///
/// Dirs with a .nomedia/.noimage file will be ignored. The returned stream
/// would emit either File data or an exception
/// would emit either File data or ExceptionEvent
Stream<dynamic> call(Account account, File root) async* {
final dataStream = ScanDir(fileRepo)(account, root);
await for (final d in dataStream) {
if (d is Exception || d is Error) {
if (d is ExceptionEvent) {
yield d;
continue;
}

View file

@ -7,6 +7,7 @@ import 'package:nc_photos/entity/exif.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/metadata_task_manager.dart';
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/use_case/get_file_binary.dart';
@ -20,11 +21,11 @@ class UpdateMissingMetadata {
/// Update metadata for all files that support one under a dir recursively
///
/// Dirs with a .nomedia/.noimage file will be ignored. The returned stream
/// would emit either File data (for each updated files) or an exception
/// would emit either File data (for each updated files) or ExceptionEvent
Stream<dynamic> call(Account account, File root) async* {
final dataStream = ScanMissingMetadata(fileRepo)(account, root);
await for (final d in dataStream) {
if (d is Exception || d is Error) {
if (d is ExceptionEvent) {
yield d;
continue;
}
@ -73,10 +74,10 @@ class UpdateMissingMetadata {
metadata: OrNull(metadataObj),
);
yield file;
} catch (e, stacktrace) {
} catch (e, stackTrace) {
_log.severe("[call] Failed while updating metadata: ${file.path}", e,
stacktrace);
yield e;
stackTrace);
yield ExceptionEvent(e, stackTrace);
}
}
}