I have a simple setting:
lifecycleScope.launch {
val result = test()
}
suspend fun test(): Result<Unit> = withContext(Dispatchers.IO) {
Result.failure(IllegalStateException("QWER"))
}
Actual result: The code above is crashing with: java.lang.IllegalStateException: QWER
Expected result: Result object returned as expected
Im using kotlin 1.4.10 and coroutines 1.3.9. Im using a kotlin.Result object as a return type, for that I have:
kotlinOptions {
freeCompilerArgs = ["-Xallow-result-return-type"]
}
Another thing is if I'm executing the coroutine with the main context(Dispatchers.Main) everything works as expected .