You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaScript allows to throw strings, but it leads to ClassCastException is thrown in kotlinx-coroutines-core
Looks createCauseException is the root cause of ClassCastException , String is not Throwable so it is trying to be cast to ParentJob
classTestClient2 {
@Test
funtestThrowString() = runTest {
val job = launch {
println("throwing a JS string")
throwIllegalStateException("EMPTY") //In JS everything can be thrown, even a String!println("not executed....")
}
println("waiting for job")
job.join()
}
}
The text was updated successfully, but these errors were encountered:
Instead of assuming non-Throwable values are ParentJob
We can wrap them in an IllegalStateException with a descriptive message
This maintains type safety while handling JavaScript's flexible throwing behavior
( LMK if this approach is correct I'd love to work on it )
Unfortunately, I see no way of fixing this on our side. To wrap an exception, you first have to catch it somehow, and I didn't succeed in doing that without writing custom js("") blocks, and certainly not in the common code of our multiplatform library. I opened an issue for Kotlin/JS: https://youtrack.jetbrains.com/issue/KT-73710/No-way-to-catch-every-JS-error-in-common-code UPD: catch (e: dynamic) does work in JS without custom js("") blocks, but this, too, doesn't compile in common code.
Describe the bug
https://youtrack.jetbrains.com/issue/KT-72174/Kotlin-JS-Coroutines-throwing-JS-string-does-not-stop-the-job
JavaScript allows to throw strings, but it leads to
ClassCastException
is thrown inkotlinx-coroutines-core
Looks
createCauseException
is the root cause ofClassCastException
,String
is notThrowable
so it is trying to be cast toParentJob
kotlinx.coroutines/kotlinx-coroutines-core/common/src/JobSupport.kt
Lines 748 to 752 in 6c6df2b
Provide a Reproducer
The text was updated successfully, but these errors were encountered: