Skip to content

An open-source cross-platform alternative to AirDrop

feat: improve error handling per file

Tien Do Namdfea0c7b0bbb
diff --git a/assets/CHANGELOG.md b/assets/CHANGELOG.md
index 8a8c7cf6..a316c1da 100644
--- a/assets/CHANGELOG.md
+++ b/assets/CHANGELOG.md
@@ -2,6 +2,7 @@
- feat: received file history
- feat: show recent IP addresses in manual IP input
+- feat: improve error handling and add possibility to show exact error message for debugging
- feat: add unencrypted HTTP mode (for debugging)
- feat: separate language settings page
- feat: message input is horizontally scrollable when multiline is unselected
diff --git a/lib/model/send/sending_file.dart b/lib/model/send/sending_file.dart
index e619b30a..2b9f97e6 100644
--- a/lib/model/send/sending_file.dart
+++ b/lib/model/send/sending_file.dart
@@ -14,5 +14,6 @@ class SendingFile with _$SendingFile {
required AssetEntity? asset, // for thumbnails
required String? path, // android, iOS, desktop
required List<int>? bytes, // web
+ required String? errorMessage, // when status == failed
}) = _SendingFile;
}
diff --git a/lib/model/server/receiving_file.dart b/lib/model/server/receiving_file.dart
index 828610e4..6877ed83 100644
--- a/lib/model/server/receiving_file.dart
+++ b/lib/model/server/receiving_file.dart
@@ -13,5 +13,6 @@ class ReceivingFile with _$ReceivingFile {
required String? desiredName, // not null when accepted
required String? path, // when finished
required bool savedToGallery, // when finished
+ required String? errorMessage, // when status == failed
}) = _ReceivingFile;
}
diff --git a/lib/pages/progress_page.dart b/lib/pages/progress_page.dart
index 99e76141..e7a2bb7d 100644
--- a/lib/pages/progress_page.dart
+++ b/lib/pages/progress_page.dart
@@ -13,6 +13,7 @@ import 'package:localsend_app/util/file_speed_helper.dart';
import 'package:localsend_app/util/platform_check.dart';
import 'package:localsend_app/widget/custom_progress_bar.dart';
import 'package:localsend_app/widget/dialogs/cancel_session_dialog.dart';
+import 'package:localsend_app/widget/dialogs/error_dialog.dart';
import 'package:localsend_app/widget/file_thumbnail.dart';
import 'package:open_filex/open_filex.dart';
import 'package:routerino/routerino.dart';
@@ -161,6 +162,15 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {
filePath = null;
}
+ final String? errorMessage;
+ if (receiveState != null) {
+ errorMessage = receiveState.files[file.id]!.errorMessage;
+ } else if (sendState != null) {
+ errorMessage = sendState.files[file.id]!.errorMessage;
+ } else {
+ errorMessage = null;
+ }
+
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: InkWell(
@@ -211,9 +221,31 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {
),
)
else
- Text(
- savedToGallery ? t.progressPage.savedToGallery : fileStatus.label,
- style: TextStyle(color: fileStatus.getColor(context)),
+ Row(
+ children: [
+ Flexible(
+ child: Text(
+ savedToGallery ? t.progressPage.savedToGallery : fileStatus.label,
+ style: TextStyle(color: fileStatus.getColor(context)),
+ ),
+ ),
+ if (errorMessage != null)
+ ...[
+ const SizedBox(width: 5),
+ InkWell(
+ onTap: () {
+ showDialog(
+ context: context,
+ builder: (_) => ErrorDialog(error: errorMessage!),
+ );
+ },
+ child: const Padding(
+ padding: EdgeInsets.symmetric(horizontal: 5),
+ child: Icon(Icons.info, color: Colors.orange, size: 20),
+ ),
+ ),
+ ],
+ ],
),
],
),
diff --git a/lib/provider/network/send_provider.dart b/lib/provider/network/send_provider.dart
index b238fa77..8198cf18 100644
--- a/lib/provider/network/send_provider.dart
+++ b/lib/provider/network/send_provider.dart
@@ -64,6 +64,7 @@ class SendNotifier extends StateNotifier<SendState?> {
asset: file.asset,
path: file.path,
bytes: file.bytes,
+ errorMessage: null,
),
);
}))),
@@ -163,9 +164,9 @@ class SendNotifier extends StateNotifier<SendState?> {
}
print('Sending ${file.file.fileName}');
- state = state?.withFileStatus(file.file.id, FileStatus.sending);
+ state = state?.withFileStatus(file.file.id, FileStatus.sending, null);
- bool hasErrorForFile = false;
+ String? fileError;
try {
final cancelToken = CancelToken();
state = state?.copyWith(cancelToken: cancelToken);
@@ -185,12 +186,8 @@ class SendNotifier extends StateNotifier<SendState?> {
},
cancelToken: cancelToken,
);
- } on DioError catch (e) {
- hasErrorForFile = true;
- hasError = true;
- print(e);
} catch (e, st) {
- hasErrorForFile = true;
+ fileError = e.humanErrorMessage;
hasError = true;
print(e);
print(st);
@@ -200,7 +197,7 @@ class SendNotifier extends StateNotifier<SendState?> {
// session already closed
return;
} else {
- state = state?.withFileStatus(file.file.id, hasErrorForFile ? FileStatus.failed : FileStatus.finished);
+ state = state?.withFileStatus(file.file.id, fileError != null ? FileStatus.failed : FileStatus.finished, fileError);
}
}
@@ -226,9 +223,12 @@ class SendNotifier extends StateNotifier<SendState?> {
}
extension on SendState {
- SendState withFileStatus(String fileId, FileStatus status) {
+ SendState withFileStatus(String fileId, FileStatus status, String? errorMessage) {
return copyWith(
- files: {...files}..update(fileId, (file) => file.copyWith(status: status)),
+ files: {...files}..update(fileId, (file) => file.copyWith(
+ status: status,
+ errorMessage: errorMessage,
+ )),
);
}
}
diff --git a/lib/provider/network/server_provider.dart b/lib/provider/network/server_provider.dart
index 51009e38..59e24b89 100644
--- a/lib/provider/network/server_provider.dart
+++ b/lib/provider/network/server_provider.dart
@@ -184,6 +184,7 @@ class ServerNotifier extends StateNotifier<ServerState?> {
desiredName: null,
path: null,
savedToGallery: false,
+ errorMessage: null,
),
},
startTime: null,
@@ -241,6 +242,7 @@ class ServerNotifier extends StateNotifier<ServerState?> {
desiredName: desiredName,
path: null,
savedToGallery: false,
+ errorMessage: null,
),
);
}),
@@ -340,6 +342,7 @@ class ServerNotifier extends StateNotifier<ServerState?> {
status: FileStatus.finished,
path: saveToGallery ? null : destinationPath,
savedToGallery: saveToGallery,
+ errorMessage: null,
),
);
@@ -363,6 +366,7 @@ class ServerNotifier extends StateNotifier<ServerState?> {
status: FileStatus.failed,
path: null,
savedToGallery: false,
+ errorMessage: e.toString(),
),
);
print(e);
@@ -522,6 +526,7 @@ extension on ReceiveState {
required FileStatus status,
required String? path,
required bool savedToGallery,
+ required String? errorMessage,
}) {
return copyWith(
files: {...files}..update(
@@ -530,6 +535,7 @@ extension on ReceiveState {
status: status,
path: path,
savedToGallery: savedToGallery,
+ errorMessage: errorMessage,
),
),
);