Add catchingExceptions method to replace runCatching (#4797)

- Add `runCatchingExceptions` and `mapCatchingExceptions` to replace `runCatching` and `mapCatching`.
- Make `tryOrNull { ... }` catch only exceptions too.
- Apply the changes to the whole project.
- Add new Rust fakes for tests to handle the code that's now unblocked - previously it just threw an `UnsatisfiedLinkError` which we ignored.
- Add a new `detekt-rules` project with a `RunCatchingRule` to prevent `runCatching` and `mapCatching` usages.
This commit is contained in:
Jorge Martin Espinosa
2025-06-04 09:02:26 +02:00
committed by GitHub
parent 01d6012760
commit 58a3ea8b1f
144 changed files with 716 additions and 375 deletions

View File

@@ -27,6 +27,7 @@ import io.element.android.libraries.preferences.api.store.SessionPreferencesStor
import io.element.android.services.appnavstate.api.ActiveRoomsHolder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlin.coroutines.cancellation.CancellationException
class SharePresenter @AssistedInject constructor(
@Assisted private val intent: Intent,
@@ -89,12 +90,21 @@ class SharePresenter @AssistedInject constructor(
)
filesToShare
.map { fileToShare ->
mediaSender.sendMedia(
val result = mediaSender.sendMedia(
uri = fileToShare.uri,
mimeType = fileToShare.mimeType,
).isSuccess
)
// If the coroutine was cancelled, destroy the room and rethrow the exception
val cancellationException = result.exceptionOrNull() as? CancellationException
if (cancellationException != null) {
if (activeRoomsHolder.getActiveRoomMatching(matrixClient.sessionId, roomId) == null) {
room.destroy()
}
throw cancellationException
}
result.isSuccess
}
.all { it }
.all { isSuccess -> isSuccess }
.also {
if (activeRoomsHolder.getActiveRoomMatching(matrixClient.sessionId, roomId) == null) {
room.destroy()

View File

@@ -24,7 +24,7 @@ open class ShareStateProvider : PreviewParameterProvider<ShareState> {
)
),
aShareState(
shareAction = AsyncAction.Failure(Throwable("error")),
shareAction = AsyncAction.Failure(RuntimeException("error")),
),
)
}