From 8839b62ccdb5e5c5b0b9de377a59490c89ea1e1d Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Mon, 2 Dec 2024 16:14:03 +0100 Subject: [PATCH 1/2] fix: Catch openInputStream crash and count it as a "failed file" --- .../ui/screen/newtransfer/ImportationFilesManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt index 682e0b314..179e090b8 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt @@ -118,7 +118,7 @@ class ImportationFilesManager @Inject constructor( } private fun openInputStream(uri: Uri): InputStream? { - return appContext.contentResolver.openInputStream(uri) ?: run { + return runCatching { appContext.contentResolver.openInputStream(uri) }.getOrNull() ?: run { SentryLog.w(ImportLocalStorage.TAG, "During local copy of the file openInputStream returned null") null } From beef9afb4a4e2a25fa1b4f4382013c5fffedea97 Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Mon, 2 Dec 2024 16:21:36 +0100 Subject: [PATCH 2/2] refactor: Fix sentry log to only log it when the openInputStream willingly returns null --- .../ui/screen/newtransfer/ImportationFilesManager.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt index 179e090b8..22d115628 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt @@ -118,10 +118,11 @@ class ImportationFilesManager @Inject constructor( } private fun openInputStream(uri: Uri): InputStream? { - return runCatching { appContext.contentResolver.openInputStream(uri) }.getOrNull() ?: run { - SentryLog.w(ImportLocalStorage.TAG, "During local copy of the file openInputStream returned null") - null - } + return runCatching { appContext.contentResolver.openInputStream(uri) } + .onSuccess { + if (it == null) SentryLog.w(ImportLocalStorage.TAG, "During local copy of the file openInputStream returned null") + } + .getOrNull() } private fun getRestoredFileUi(localFiles: Array): List {