Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
13.09k stars 1.86k forks source link

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

Open Omico opened 3 months ago

Omico commented 3 months ago

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.

dkhalanskyjb commented 3 months ago

@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 commented 3 months ago

@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 commented 3 months ago

@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 commented 3 months ago

@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 https://github.com/Kotlin/kotlinx.coroutines/issues/4213#issuecomment-2293451046, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMT73TOIPGEYY4WUV2TESSTZRXYNBAVCNFSM6AAAAABMOSKBJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGQ2TCMBUGY . You are receiving this because you were mentioned.Message ID: @.***>

Omico commented 3 months ago

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 commented 3 months ago

@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.