Skip to content

[WASM] JsException: Exception was thrown while running JavaScript code kotlinx.coroutines.error_$external_fun #4213

@Omico

Description

@Omico

Describe the bug

The webview is blocked.

Provide a Reproducer

git clone https://github.com/OmicoDev/wwm/tree/optimize-loading-font-on-wasm
Run wwm.web.run run configuration.
See the browser console.

Activity

dkhalanskyjb

dkhalanskyjb commented on Aug 14, 2024

@dkhalanskyjb
Contributor

@igoriakovlev, looking into this, I see the following stack trace:

    error_$external_fun wasmJs.uninstantiated.mjs:4786
    error_$external_fun__externalAdapter wasmJs.wasm:5090143
    propagateExceptionFinalResort wasmJs.wasm:5092112
    handleUncaughtCoroutineException wasmJs.wasm:5044474
    handleCoroutineException wasmJs.wasm:4922944

Looks like console.error doesn't work for some reason. What could be the reason, and what can we use instead?

dkhalanskyjb

dkhalanskyjb commented on Aug 16, 2024

@dkhalanskyjb
Contributor

@Omico, in any case, the reason you're seeing this is that some coroutines that in your codebase are throwing uncaught exceptions. Please read https://kotlinlang.org/docs/exception-handling.html . The issue on our side is that the error message you get is unhelpful for identifying the problem.

igoriakovlev

igoriakovlev commented on Aug 16, 2024

@igoriakovlev
Contributor

@dkhalanskyjb It works in a same way as in Kotlin/Js. Kotlin/Wasm 2.0.10 does not supports yet js exception info retrieving (now in WIP) so the only thing we can log now is JSException's message.

dkhalanskyjb

dkhalanskyjb commented on Aug 16, 2024

@dkhalanskyjb
Contributor
Omico

Omico commented on Aug 16, 2024

@Omico
Author

I'm unfamiliar with web development, but based on what I know now, I highly suspect this issue is because the content I want to store exceeds the localstorage limit. https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria#web_storage

However, the Coroutines API cannot provide any helpful information for this error. I hope we can have a better debug experience in similar scenarios.

igoriakovlev

igoriakovlev commented on Aug 16, 2024

@igoriakovlev
Contributor

@igoriakovlev, I don't think it works the same way on JS. On JS, console.error works and prints and error to the log, but on Wasm, it crashes for some reason.

On Fri, Aug 16, 2024, 2:49 PM igoriakovlev @.> wrote: @dkhalanskyjb https://github.com/dkhalanskyjb It works in a same way as in Kotlin/Js. Kotlin/Wasm 2.0.10 does not supports yet js exception info retrieving (now in WIP) so the only thing we can log now is JSException's message. — Reply to this email directly, view it on GitHub <#4213 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMT73TOIPGEYY4WUV2TESSTZRXYNBAVCNFSM6AAAAABMOSKBJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGQ2TCMBUGY . You are receiving this because you were mentioned.Message ID: @.>

@dkhalanskyjb I do not see that it craches, for me it prints the error and stack for the place where console.error was called. The same way as KotlinJs do.

dosier

dosier commented on Dec 29, 2024

@dosier

I am having this issue too:

Using compose 1.8.0-alpha01 and kotlin 2.1.0


  | kotlinx.coroutines.error_$external_fun | @ | composeApp.uninstantiated.mjs:191
-- | -- | -- | --
  | $kotlinx.coroutines.error_$external_fun__externalAdapter | @ | 58832f8….wasm:0x46a75b
  | $kotlinx.coroutines.internal.propagateExceptionFinalResort | @ | 58832f8….wasm:0x46b055
  | $kotlinx.coroutines.internal.handleUncaughtCoroutineException | @ | 58832f8….wasm:0x45e826
  | $kotlinx.coroutines.handleCoroutineException | @ | 58832f8….wasm:0x43381a
  | $kotlinx.coroutines.StandaloneCoroutine.handleJobException | @ | 58832f8….wasm:0x42fe1e
  | $kotlinx.coroutines.JobSupport.finalizeFinishingState | @ | 58832f8….wasm:0x436ed5
  | $kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath | @ | 58832f8….wasm:0x4396d8
  | $kotlinx.coroutines.JobSupport.tryMakeCompleting | @ | 58832f8….wasm:0x439484
  | $kotlinx.coroutines.JobSupport.makeCompletingOnce | @ | 58832f8….wasm:0x439347
  | $kotlinx.coroutines.AbstractCoroutine.resumeWith | @ | 58832f8….wasm:0x42f89d
  | $kotlin.coroutines.CoroutineImpl.resumeWith | @ | 58832f8….wasm:0x3f29c7
  | $kotlinx.coroutines.DispatchedTask.run | @ | 58832f8….wasm:0x46001d
  | $androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$slambda$lambda.invoke | @ | 58832f8….wasm:0x75884c
  | $androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$slambda$lambda.invoke | @ | 58832f8….wasm:0x758857
  | $androidx.compose.ui.platform.FlushCoroutineDispatcher.performRun | @ | 58832f8….wasm:0x7593fc
  | $androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$slambda.doResume | @ | 58832f8….wasm:0x758a7c
  | $androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$slambda.invoke | @ | 58832f8….wasm:0x7589cc
  | $androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$slambda.invoke | @ | 58832f8….wasm:0x758a16
  | $kotlin.coroutines.intrinsics.<no name provided>.doResume | @ | 58832f8….wasm:0x3f2f25
  | $kotlin.coroutines.CoroutineImpl.resumeWith | @ | 58832f8….wasm:0x3f290c
  | $kotlinx.coroutines.DispatchedTask.run | @ | 58832f8….wasm:0x46001d
  | $kotlinx.coroutines.MessageQueue.process | @ | 58832f8….wasm:0x4695fd
  | $kotlinx.coroutines.WindowMessageQueue$process$ref.invoke | @ | 58832f8….wasm:0x46a9a4
  | $kotlinx.coroutines.WindowMessageQueue$process$ref.invoke | @ | 58832f8….wasm:0x46a9ae
  | $kotlin.js.__callFunction_(()->Unit) | @ | 58832f8….wasm:0x3ed9dd
  | eval | @ | composeApp.uninstantiated.mjs:126
  | handler | @ | composeApp.uninstantiated.mjs:200
  | postMessage |   |  
  | eval | @ | composeApp.uninstantiated.mjs:195
  | kotlinx.coroutines.__callJsClosure_(()->Unit) | @ | composeApp.uninstantiated.mjs:194
  | $kotlinx.coroutines.__JsClosureToKotlinClosure_(()->Unit).invoke | @ | 58832f8….wasm:0x46ab3b
  | $kotlinx.coroutines.__JsClosureToKotlinClosure_(()->Unit).invoke | @ | 58832f8….wasm:0x46ab43
  | $kotlinx.coroutines.WindowMessageQueue.reschedule | @ | 58832f8….wasm:0x46aaa9
  | $kotlinx.coroutines.MessageQueue.process | @ | 58832f8….wasm:0x4696c2
  | $kotlinx.coroutines.WindowMessageQueue$process$ref.invoke | @ | 58832f8….wasm:0x46a942
  | $kotlinx.coroutines.WindowMessageQueue$process$ref.invoke | @ | 58832f8….wasm:0x46a94c
  | $kotlin.js.__callFunction_(()->Unit) | @ | 58832f8….wasm:0x3ed9dd
  | eval | @ | composeApp.uninstantiated.mjs:126
  | Promise.then |   |  
  | eval | @ | composeApp.uninstantiated.mjs:193
  | kotlinx.coroutines.__callJsClosure_(()->Unit) | @ | composeApp.uninstantiated.mjs:194
  | $kotlinx.coroutines.__JsClosureToKotlinClosure_(()->Unit).invoke | @ | 58832f8….wasm:0x46ab3b
  | $kotlinx.coroutines.__JsClosureToKotlinClosure_(()->Unit).invoke | @ | 58832f8….wasm:0x46ab43
  | $kotlinx.coroutines.WindowMessageQueue.schedule | @ | 58832f8….wasm:0x46aa6f
  | $kotlinx.coroutines.MessageQueue.enqueue | @ | 58832f8….wasm:0x469566
  | $kotlinx.coroutines.WindowDispatcher.dispatch | @ | 58832f8….wasm:0x468bcb
  | $kotlinx.coroutines.JsMainDispatcher.dispatch | @ | 58832f8….wasm:0x469b3a
  | $kotlinx.coroutines.internal.DispatchedContinuation.resumeWith | @ | 58832f8….wasm:0x45ee80
  | $kotlin.coroutines.startCoroutine | @ | 58832f8….wasm:0x3ca49a
  | $kotlinx.coroutines.CoroutineStart.invoke | @ | 58832f8….wasm:0x4341b3
  | $kotlinx.coroutines.AbstractCoroutine.start | @ | 58832f8….wasm:0x42f996
  | $kotlinx.coroutines.channels.produce | @ | 58832f8….wasm:0x44a941
  | $kotlinx.coroutines.channels.produce$default | @ | 58832f8….wasm:0x44a9c9
  | $kotlinx.coroutines.flow.internal.ChannelFlow.produceImpl | @ | 58832f8….wasm:0x451bf8
  | $kotlinx.coroutines.flow.internal.ChannelFlow$collect$slambda.doResume | @ | 58832f8….wasm:0x451912
  | $kotlinx.coroutines.flow.internal.ChannelFlow$collect$slambda.invoke | @ | 58832f8….wasm:0x45183b
  | $kotlinx.coroutines.flow.internal.ChannelFlow$collect$slambda.invoke | @ | 58832f8….wasm:0x451885
  | $kotlinx.coroutines.intrinsics.startUndispatchedOrReturn | @ | 58832f8….wasm:0x462d53
  | $kotlinx.coroutines.coroutineScope$lambda.invoke | @ | 58832f8….wasm:0x433d94
  | $kotlinx.coroutines.coroutineScope$lambda.invoke | @ | 58832f8….wasm:0x433ddc
  | $kotlinx.coroutines.$coroutineScopeCOROUTINE$6.doResume | @ | 58832f8….wasm:0x433ed7
  | $kotlinx.coroutines.coroutineScope | @ | 58832f8….wasm:0x433b37
  | $kotlinx.coroutines.flow.internal.ChannelFlow.collect | @ | 58832f8….wasm:0x451c1e
  | $kotlinx.coroutines.flow.internal.$collectCOROUTINE$39.doResume | @ | 58832f8….wasm:0x4513bb
  | $kotlinx.coroutines.flow.internal.ChannelFlowOperator.collect | @ | 58832f8….wasm:0x45151f
  | $kotlinx.coroutines.flow.collect | @ | 58832f8….wasm:0x45cf4b
  | $kotlinx.coroutines.flow.collectLatest | @ | 58832f8….wasm:0x45cf7e
  | $kotlinx.coroutines.flow.launchSharing$slambda.doResume | @ | 58832f8….wasm:0x45a10c
  | $kotlinx.coroutines.flow.launchSharing$slambda.invoke | @ | 58832f8….wasm:0x459f23
  | $kotlinx.coroutines.flow.launchSharing$slambda.invoke | @ | 58832f8….wasm:0x459f6d
  | $kotlinx.coroutines.intrinsics.startCoroutineUndispatched | @ | 58832f8….wasm:0x4630dc
  | $kotlinx.coroutines.CoroutineStart.invoke | @ | 58832f8….wasm:0x4341c3
  | $kotlinx.coroutines.AbstractCoroutine.start | @ | 58832f8….wasm:0x42f996
  | $kotlinx.coroutines.launch | @ | 58832f8….wasm:0x42fcec
  | $kotlinx.coroutines.flow.launchSharing | @ | 58832f8….wasm:0x4599ad
  | $kotlinx.coroutines.flow.stateIn | @ | 58832f8….wasm:0x4595a0
  | $me.app.shared.component.AppComponentContextImpl.stateInComponent | @ | AppComponentContextImpl.kt:42
  | $me.app.shared.ui.poker.generator.ConfigureGameDetailsComponentImpl.stateInComponent | @ | 58832f8….wasm:0x958679
  | $me.app.shared.component.AppComponentContext.stateInComponent$default | @ | 58832f8….wasm:0x94746a
  | $me.app.shared.ui.generator.ConfigureGameDetailsComponentImpl.<init> | @ | ConfigureGameDetailsComponent.kt:88
  | $me.app.shared.ui.generator.HandCreationComponentImpl.<init> | @ | HandCreationComponent.kt:55
  | $me.app.shared.component.RootComponentImpl.<init> | @ | RootComponentImpl.kt:19
  | $main | @ | WasmApp.kt:27
  | $_initialize | @ | 58832f8….wasm:0x973a83
  | instantiate | @ | composeApp.uninstantiated.mjs:5863
  | await in instantiate |   |  
  | eval | @ | composeApp.mjs:7
  | await in eval |   |  
  | __webpack_require__.a | @ | composeApp.js:458
  | eval | @ | composeApp.mjs:1
  | ./kotlin/composeApp.mjs | @ | composeApp.js:343
  | __webpack_require__ | @ | composeApp.js:392
  | (anonymous) | @ | composeApp.js:1527
  | (anonymous) | @ | composeApp.js:1530
  | webpackUniversalModuleDefinition | @ | composeApp.js:17
  | (anonymous) | @ | composeApp.js:18
  ```
dkhalanskyjb

dkhalanskyjb commented on Jul 28, 2025

@dkhalanskyjb
Contributor

Will be fixed in 6f0fb66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dosier@Omico@dkhalanskyjb@igoriakovlev

        Issue actions

          [WASM] JsException: Exception was thrown while running JavaScript code kotlinx.coroutines.error_$external_fun · Issue #4213 · Kotlin/kotlinx.coroutines