From e377482660d08c371d88315b64c2e3644713d77e Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:10:59 -0300 Subject: [PATCH 1/2] Update upload_cubit.dart refactor error handling to avoid calling onError and addError --- lib/blocs/upload/upload_cubit.dart | 37 +++++------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/lib/blocs/upload/upload_cubit.dart b/lib/blocs/upload/upload_cubit.dart index 751bf01569..1cf665d9f6 100644 --- a/lib/blocs/upload/upload_cubit.dart +++ b/lib/blocs/upload/upload_cubit.dart @@ -440,7 +440,7 @@ class UploadCubit extends Cubit { ); } catch (error, stacktrace) { logger.e('error mounting the upload', error, stacktrace); - addError(error); + _emitError(error); } } @@ -645,14 +645,6 @@ class UploadCubit extends Cubit { uploadController.onDone( (tasks) async { - logger.d('Upload folders and files finished... Verifying results'); - - if (tasks.any((element) => element.status == UploadStatus.failed)) { - logger.e('One or more tasks failed. Emitting error'); - // if any of the files failed, we should throw an error - addError(Exception('Error uploading')); - } - emit(UploadComplete()); unawaited(_profileCubit.refreshBalance()); @@ -766,30 +758,15 @@ class UploadCubit extends Cubit { uploadController.onDone( (tasks) async { - logger.d('Upload files finished... Verifying results'); - - bool uploadSucced = true; - - if (tasks.any((element) => element.status == UploadStatus.failed)) { - logger.e('One or more tasks failed. Emitting error'); - // if any of the files failed, we should throw an error - addError(Exception('Error uploading')); - - PlausibleEventTracker.trackUploadFailure(); - uploadSucced = false; - } - unawaited(_profileCubit.refreshBalance()); - // all files are uploaded - - logger.i('Upload finished with success'); + logger.i( + 'Upload finished with success. Number of tasks: ${tasks.length}', + ); emit(UploadComplete()); - if (uploadSucced) { - PlausibleEventTracker.trackUploadSuccess(); - } + PlausibleEventTracker.trackUploadSuccess(); }, ); @@ -976,8 +953,7 @@ class UploadCubit extends Cubit { emit(UploadFailure(error: UploadErrors.unknown)); } - @override - void onError(Object error, StackTrace stackTrace) { + void _emitError(Object error) { if (error is TurboUploadTimeoutException) { emit(UploadFailure(error: UploadErrors.turboTimeout)); @@ -985,7 +961,6 @@ class UploadCubit extends Cubit { } emit(UploadFailure(error: UploadErrors.unknown)); - super.onError(error, stackTrace); } Future cancelUpload() async { From 493c094dbe5fecd3b2aa3879461f325bfc0975b9 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:19:29 -0300 Subject: [PATCH 2/2] handle Null error throwing a proper exception --- lib/services/arweave/arweave_service.dart | 15 +++++++++++++-- .../arweave/arweave_service_exception.dart | 10 ++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 lib/services/arweave/arweave_service_exception.dart diff --git a/lib/services/arweave/arweave_service.dart b/lib/services/arweave/arweave_service.dart index 3aa4da8e38..781e18a946 100644 --- a/lib/services/arweave/arweave_service.dart +++ b/lib/services/arweave/arweave_service.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:ardrive/core/crypto/crypto.dart'; import 'package:ardrive/entities/entities.dart'; +import 'package:ardrive/services/arweave/arweave_service_exception.dart'; import 'package:ardrive/services/arweave/error/gateway_error.dart'; import 'package:ardrive/services/arweave/get_segmented_transaction_from_drive_strategy.dart'; import 'package:ardrive/services/services.dart'; @@ -117,8 +118,18 @@ class ArweaveService { /// Returns the pending transaction fees of the specified address that is not reflected by `getWalletBalance()`. Future getPendingTxFees(String address) async { - final query = await graphQLRetry.execute(PendingTxFeesQuery( - variables: PendingTxFeesArguments(walletAddress: address))); + final query = await graphQLRetry.execute( + PendingTxFeesQuery( + variables: PendingTxFeesArguments( + walletAddress: address, + ), + ), + ); + + if (query.data == null) { + throw ArweaveServiceException( + 'Error fetching pending transaction fees. The query `PendingTxFeesQuery` returned null'); + } return query.data!.transactions.edges .map((edge) => edge.node) diff --git a/lib/services/arweave/arweave_service_exception.dart b/lib/services/arweave/arweave_service_exception.dart new file mode 100644 index 0000000000..3fb2ced6d8 --- /dev/null +++ b/lib/services/arweave/arweave_service_exception.dart @@ -0,0 +1,10 @@ +class ArweaveServiceException implements Exception { + final String message; + + ArweaveServiceException(this.message); + + @override + String toString() { + return 'ArweaveServiceException: $message'; + } +}