Skip to content

Commit ebe1873

Browse files
committed
Stop swallowing CancellationException on rename
runCatching catches Throwable, so the previous shape silently absorbed CancellationException and surfaced it as a RenameResult.Error. That breaks structured concurrency: a cancelled scope should propagate upwards, not be reported as a rename failure. Swap to a try/catch that rethrows CancellationException and only converts Exception into the user-visible error state.
1 parent fd27916 commit ebe1873

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/history/RenameChatViewModel.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.lifecycle.ViewModel
2020
import com.duckduckgo.anvil.annotations.ContributesViewModel
2121
import com.duckduckgo.app.di.AppCoroutineScope
2222
import com.duckduckgo.di.scopes.FragmentScope
23+
import kotlinx.coroutines.CancellationException
2324
import kotlinx.coroutines.CoroutineScope
2425
import kotlinx.coroutines.channels.BufferOverflow
2526
import kotlinx.coroutines.channels.Channel
@@ -39,9 +40,14 @@ class RenameChatViewModel @Inject constructor(
3940

4041
fun onSaveClicked(chatId: String, newTitle: String) {
4142
appScope.launch {
42-
runCatching { chatHistoryRepository.renameChat(chatId, newTitle.trim()) }
43-
.onSuccess { resultChannel.trySend(RenameResult.Success) }
44-
.onFailure { error -> resultChannel.trySend(RenameResult.Error(error)) }
43+
try {
44+
chatHistoryRepository.renameChat(chatId, newTitle.trim())
45+
resultChannel.trySend(RenameResult.Success)
46+
} catch (e: CancellationException) {
47+
throw e
48+
} catch (e: Exception) {
49+
resultChannel.trySend(RenameResult.Error(e))
50+
}
4551
}
4652
}
4753

0 commit comments

Comments
 (0)