From 9c9616d04752e5b47966917f8648fdbb62e05ba9 Mon Sep 17 00:00:00 2001 From: Aditya Wasan Date: Wed, 23 Mar 2022 18:18:06 +0530 Subject: fix: ignore `CancellationException` in suspend functions (#1794) * fix: ignore `CancellationException` in suspend functions Signed-off-by: Aditya Wasan * build(coroutine-utils): use `api` instead of `implementation` Co-authored-by: Harsh Shandilya Co-authored-by: Harsh Shandilya --- .../main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crypto-pgpainless/src/main/kotlin') diff --git a/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt b/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt index adcce22b..8c54d516 100644 --- a/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt +++ b/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt @@ -8,9 +8,9 @@ package dev.msfjarvis.aps.crypto import androidx.annotation.VisibleForTesting import com.github.michaelbull.result.Result -import com.github.michaelbull.result.runCatching import dev.msfjarvis.aps.crypto.KeyUtils.tryGetId import dev.msfjarvis.aps.crypto.KeyUtils.tryParseKeyring +import dev.msfjarvis.aps.util.coroutines.runSuspendCatching import java.io.File import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher @@ -28,7 +28,7 @@ constructor( override suspend fun addKey(key: PGPKey, replace: Boolean): Result = withContext(dispatcher) { - runCatching { + runSuspendCatching { if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException if (tryParseKeyring(key) == null) throw KeyManagerException.InvalidKeyException val keyFile = File(keyDir, "${tryGetId(key)}.$KEY_EXTENSION") @@ -49,7 +49,7 @@ constructor( override suspend fun removeKey(key: PGPKey): Result = withContext(dispatcher) { - runCatching { + runSuspendCatching { if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException if (tryParseKeyring(key) == null) throw KeyManagerException.InvalidKeyException val keyFile = File(keyDir, "${tryGetId(key)}.$KEY_EXTENSION") @@ -63,7 +63,7 @@ constructor( override suspend fun getKeyById(id: GpgIdentifier): Result = withContext(dispatcher) { - runCatching { + runSuspendCatching { if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException val keyFiles = keyDir.listFiles() if (keyFiles.isNullOrEmpty()) throw KeyManagerException.NoKeysAvailableException @@ -89,7 +89,7 @@ constructor( } if (matchResult != null) { - return@runCatching matchResult + return@runSuspendCatching matchResult } throw KeyManagerException.KeyNotFoundException("$id") @@ -98,10 +98,10 @@ constructor( override suspend fun getAllKeys(): Result, Throwable> = withContext(dispatcher) { - runCatching { + runSuspendCatching { if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException val keyFiles = keyDir.listFiles() - if (keyFiles.isNullOrEmpty()) return@runCatching emptyList() + if (keyFiles.isNullOrEmpty()) return@runSuspendCatching emptyList() keyFiles.map { keyFile -> PGPKey(keyFile.readBytes()) }.toList() } } -- cgit v1.2.3