David Kubecka
11/05/2024, 3:20 PMfun <R, E : ApiError> withApiError(block: Raise<E>.() -> R): R = recover(block) { error -> error(error) }
context(Raise<ApiError>)
fun <T> withAccount(productHashedId: String, block: Account.() -> T): T = TODO()
fun main() =
withApiError {
withAccount {
withApiError { // simplified example - it's not clear why I need this but it doesn't matter here
// do something with Raise<ApiError> and Account contexts
}
}
}
Sonar is complaining about Unused coroutines Flow
on this snippet. Does it make any sense? I'm not explicitly using coroutines in my code.
Here's a description of the relevant Sonar check: https://rules.sonarsource.com/kotlin/RSPEC-6314/Riccardo Cardin
11/06/2024, 11:32 AMRiccardo Cardin
11/06/2024, 11:33 AMRiccardo Cardin
11/06/2024, 11:34 AMwithAccount
does something subtle?David Kubecka
11/06/2024, 4:21 PMcontext(Raise<ApiError>)
fun <T> withAccount(accountId: String, block: Account.() -> T): T =
with(repo.getByProductHashedId(accountId), block)
If there are no coroutines in the Raise DSL then Sonar really just got super confused 😄Riccardo Cardin
11/06/2024, 4:41 PMDavid Kubecka
11/06/2024, 4:42 PMRiccardo Cardin
11/06/2024, 4:43 PMDavid Kubecka
11/06/2024, 4:44 PMJpaRepository
Riccardo Cardin
11/06/2024, 4:44 PMRiccardo Cardin
11/06/2024, 4:44 PMDavid Kubecka
11/06/2024, 4:45 PMDavid Kubecka
11/06/2024, 4:47 PMDavid Kubecka
11/07/2024, 10:56 AMCancellationException
alias which is in the kotlin.coroutines.cancellation
package. So perhaps here is a tiny connection to coroutines which might have confused sonar.Riccardo Cardin
11/07/2024, 10:58 AMcatch
in the fold
function is transparent to the CancellationException
David Kubecka
11/07/2024, 11:12 AMRaiseCancellationException
(which extends CancellationException
) is actually used as the main short-circuiting mechanism in the RaiseDSL. Moreover, I don't see any immediate reason why RaiseCancellationException
extends CancellationException
in the first place. Perhaps it's needed in other parts of the DSL but not in the central fold
function.