runCatching wraps code in a coroutine and turns its cancellation into a failed result
What it finds
runCatching catches every Throwable, CancellationException included. In a coroutine that means a cancelled job keeps running after the block, with the cancellation stored as an ordinary failure. Catching the expected exceptions, or rethrowing cancellation, keeps cancellation working.
From the rule's source, run_catching_in_coroutine.rs.
suspend fun load(): Result<Int> { return runCatching { fetch() }tx0 reports: runCatching in a coroutine also catches its cancellation} fun parse(text: String): Result<Int> = runCatching { text.toInt() } Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:run-catching-in-coroutine" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:run-catching-in-coroutine] reason="..."tx0 explain tx0/kotlin:run-catching-in-coroutine shows the same in the terminal. Found a false positive? Report it.