https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

ske

08/06/2018, 4:17 PM
Is there a way to stop Kotlin from ruining stack traces when suspending?
🚧 1
🧌 1
v

Vsevolod Tolstopyatov [JB]

08/06/2018, 4:29 PM
s

ske

08/06/2018, 4:57 PM
I don't really understand that, I'm not sure that's gonna solve my issue.
Consider this code:
Copy code
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.runBlocking

suspend fun subfunction() {
    println("One")
    delay(10)
    println("Two")
}

suspend fun someMethodTree() {
    subfunction()
}

suspend fun whatever() {
    someMethodTree()
}

fun main(args: Array<String>) {
    runBlocking {
        whatever()
    }
}
The stack trace at the "One" println would contain the methods leading up to it (whatever and someMethodTree), whereas at "Two", after the suspend on delay(), it would instead show the caller as "doResume", with the rest of the stack entries missing (instead it's all event loop internals and such)
v

Vsevolod Tolstopyatov [JB]

08/06/2018, 6:01 PM
yes, that’s exactly what this issue is about. In 1.3 debugger will be able to recover stacktrace using new metadata
👍 3
s

ske

08/06/2018, 7:51 PM
Ah, even in stack traces printed at runtime?
v

Vsevolod Tolstopyatov [JB]

08/07/2018, 8:16 AM
No, we can’t change the runtime. Though maybe there will be a way to print a stacktrace using debug metadata
s

ske

08/07/2018, 12:54 PM
Any idea how something like Python or JavaScript handles the same thing? It "just kinda works" there.
v

Vsevolod Tolstopyatov [JB]

08/07/2018, 1:05 PM
By having its own runtime. Kotlin works on top of JVM, we cannot modify JVM to tell it “here is the stacktrace we want to recover”
15 Views