Skip to content

Commit ee95a66

Browse files
committed
chore: update canCatching inside suspending function rule to use runSuspendCatching
1 parent 2c7c0cb commit ee95a66

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fun updateState(action: Action) {
153153

154154
```kotlin
155155
suspend fun getData(): Result<Data> = withContext(Dispatchers.IO) {
156-
runCatching {
156+
runSuspendCatching {
157157
apiService.fetchData()
158158
}.onFailure {
159159
Logger.error("Failed", it, context = TAG)
@@ -196,6 +196,8 @@ suspend fun getData(): Result<Data> = withContext(Dispatchers.IO) {
196196
- ALWAYS log errors at the final handling layer where the error is acted upon, not in intermediate layers that just propagate it
197197
- ALWAYS use the Result API instead of try-catch
198198
- NEVER wrap methods returning `Result<T>` in try-catch
199+
- ALWAYS use `runSuspendCatching` (from `ext/Coroutines.kt`) instead of `runCatching` when the block calls suspend functions or runs in a coroutine — it re-throws `CancellationException` so structured-concurrency cancellation is preserved; plain `runCatching` catches `Throwable` and swallows it. NEVER log a `CancellationException` as an error
200+
- EXCEPTION: when a `TimeoutCancellationException` from `withTimeout` must be treated as a retriable failure, use `runCatching` with an explicit `if (it is CancellationException && it !is TimeoutCancellationException) throw it` guard (e.g. `BlocktankRepo.refreshCjitEntries`)
199201
- PREFER to use `it` instead of explicit named parameters in lambdas e.g. `fn().onSuccess { log(it) }.onFailure { log(it) }`
200202
- NEVER inject ViewModels as dependencies - Only android activities and composable functions can use viewmodels
201203
- ALWAYS co-locate screen-specific ViewModels in the same package as their screen; only place ViewModels in `viewmodels/` when shared across multiple screens

0 commit comments

Comments
 (0)