Skip to content

Show async stack frames in the recovered exception stack trace #4471

@mvicsokolova

Description

@mvicsokolova

Hi!
Currently, for coroutine builders like async, which rely on the user to handle an exception (via await), we do not attach the async stack trace to the recovered exception.

For an example like this:

private suspend fun f2() {
    yield()
    if (true) throw RecoverableTestException("aaaa")
    yield()
}

private suspend fun f1() {
    yield()
    f2()
    yield()
}

private suspend fun f() {
    yield()
    f1()
    yield()
}

fun main() = runBlocking {
    val deferred = async {
        f()
    }
    deferred.await()
}

We get the following recovered exception stack trace:

kotlinx.coroutines.testing.RecoverableTestException: aaaa
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.f2(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.access$f2(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest$f2$1.invokeSuspend(StackTraceRecoveryTest.kt)
	at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest$test$1.invokeSuspend(StackTraceRecoveryTest.kt)
Caused by: kotlinx.coroutines.testing.RecoverableTestException: aaaa
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.f2(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.access$f2(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest$f2$1.invokeSuspend(StackTraceRecoveryTest.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt)
	....

And it would be great to attach the async frames as well, so that f1 and f frames would also be in the stack trace, like:

kotlinx.coroutines.testing.RecoverableTestException: aaaa
  at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.f2(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.access$f2(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest$f2$1.invokeSuspend(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.f1(StackTraceRecoveryTest.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest.f(StackTraceRecoveryTest.kt)
	at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt)
	at kotlinx.coroutines.exceptions.StackTraceRecoveryTest$test$1.invokeSuspend(StackTraceRecoveryTest.kt)
Caused by: kotlinx.coroutines.testing.RecoverableTestException: aaaa
.....

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions