is there any workaround for <https://youtrack.jetb...
# webassembly
p
is there any workaround for [WasmJs] Attach js exception object to JsException? I'm still on 2.0.10 and my tests are failing on Wasm, but I don't know why. I just want to get to the true reason of the exception to diagnose the tests, I don't care for a proper workaround in production for this bug
b
Maybe increasing stack trace limit will give you additional insights
declare and call following function before failing code
Copy code
fun setStackTraceLimit() = js("Error.stackTraceLimit = Infinity")
To get JS exception you can define
Copy code
fun <T : JsAny> jsCatch(
    throwException: (e: JsAny?) -> Unit =
        { e -> throw e?.toThrowableOrNull() ?: Exception("JS: " + e.toString()) },
    f: () -> T
): T  = js("{ try { return f(); } catch (e) { throwException(e); } }")
and wrap failing code like here:
Copy code
fun test() = runTest {
        jsCatch {
            throwsJsException()
        }
    }
p
thanks! using this technique (with a little adjustment:
Copy code
fun jsCatch(
    f: () -> Unit,
): Nothing = js("{ try { return f(); } catch (e) { console.log(e); } }")
) I found out why this test fails
👍 1
Copy code
TypeError: _this.contains is not a function
        at it.krzeminski.snakeyaml.engine.kmp.internal.contains_$external_fun (file:///Users/piotr/snakeyaml-engine-kmp/build/js/packages/snakeyaml-engine-kmp-wasm-js-test/kotlin/snakeyaml-engine-kmp-wasm-js-test.uninstantiated.mjs:4069:101)
        at <it.krzeminski:snakeyaml-engine-kmp_test>.it.krzeminski.snakeyaml.engine.kmp.internal.identityHashCode (<wasm://wasm/><it.krzeminski:snakeyaml-engine-kmp_test>-016924e6:wasm-function[16416]:0x192c24)
        at <it.krzeminski:snakeyaml-engine-kmp_test>.it.krzeminski.snakeyaml.engine.kmp.serializer.IdentitySet.add (<wasm://wasm/><it.krzeminski:snakeyaml-engine-kmp_test>-016924e6:wasm-function[16281]:0x1913d9)
        at <it.krzeminski:snakeyaml-engine-kmp_test>.it.krzeminski.snakeyaml.engine.kmp.serializer.IdentitySetTest$<init>$lambda$slambda$lambda.invoke (<wasm://wasm/><it.krzeminski:snakeyaml-engine-kmp_test>-016924e6:wasm-function[26212]:0x237051)
        at <it.krzeminski:snakeyaml-engine-kmp_test>.it.krzeminski.snakeyaml.engine.kmp.serializer.IdentitySetTest$<init>$lambda$slambda$lambda.invoke (<wasm://wasm/><it.krzeminski:snakeyaml-engine-kmp_test>-016924e6:wasm-function[26213]:0x23707c)
it has something to do with https://github.com/krzema12/snakeyaml-engine-kmp/blob/bd8ffe043fd0db28de598cbb21ce[…]tlin/it/krzeminski/snakeyaml/engine/kmp/internal/system.wasm.kt -
WeakMap
doesn't have a
contains
method, but it does have `has`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has. So it looks like an issue with our code, I'll investigate further, thanks!