Hello! I’m trying to write small kotlin wasm bench...
# webassembly
i
Hello! I’m trying to write small kotlin wasm benchmark and run it on nodejs . However, there’s some issues in my js code and I’m getting quite useless exceptions:
Copy code
EXCEPTION: JsException: Exception was thrown while running JavaScript code
JsException: Exception was thrown while running JavaScript code
Error: 
    at kotlin.captureStackTrace (file:///Users/ilyagulya/Projects/My/kotlin-wasmjs-arrays-benchmark/build/js/packages/kotlin-wasmjs-arrays-benchmark-wasm-js-wasmJsBenchmark/kotlin/kotlin-wasmjs-arrays-benchmark-wasm-js-wasmJsBenchmark.uninstantiated.mjs:16:44)
    at kotlin.captureStackTrace__externalAdapter (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:219072)
    at kotlin.Throwable.<init> (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:218731)
    at kotlin.Throwable.<init> (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:218849)
    at kotlin.js.JsException.<init> (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:220671)
    at kotlin.wasm.internal.throwJsException (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:219096)
    at kotlinx.benchmark.CommonSuiteExecutor.runBenchmark (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:266020)
    at kotlinx.benchmark.CommonSuiteExecutor$run$lambda.invoke (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:263662)
    at kotlinx.benchmark.CommonSuiteExecutor$run$lambda.invoke (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:263769)
    at kotlinx.benchmark.runWithParameters (<wasm://wasm/><kotlin-wasmjs-arrays-benchmark_wasmJsBenchmark>-0033f7ea:1:282128)
How can I fix js exception capturing? My environment right now:
Copy code
Kotlin: 2.0.0-RC2
org.jetbrains.kotlinx.benchmark: 0.4.10
Copy code
rootProject.the<NodeJsRootExtension>().apply {
    nodeVersion = "21.0.0-v8-canary20231024d0ddc81258"
    nodeDownloadBaseUrl = "<https://nodejs.org/download/v8-canary>"
}
👍 1
Ok, I’ve managed to get stack trace by wrapping whole function body to try/catch and printing error stack to console, but it would be awesome to be able to see this stack in kotlin exception instead. Is it possible?
a
@Igor Yakovlev ^^
i
quite useless exceptions
Well, having
JsException
without stack is better than not catching it at all, so it is not that useless, I think.
awesome to be able to see this stack in Kotlin exception instead
Unfortunately it is not possible with current implemented Wasm EH-proposal (maybe it is possible with a new EH-proposal? cc @Artem Kobzar). The only way now is to wrap all wasm-js interop calls with js
try-catch
block, generated by the compiler and seems not a good idea.
i
@Igor Yakovlev Surely, It’s not completely useless. I meant that it would be nicer to have a stack trace 🙂 How can I get stack trace then? Approach that I’ve used above does not always work, unfortunately. Maybe I can enable some kind of debug logging?
Currently debugging js calls from K/WASM is more of a cat and mouse play, it’s frankly inconvenient 😅
a
It's true. I will take a look closed to the new EH-proposal implementation, maybe we can do something from its side
🙏 1
I've found some points for improvement, so, hope it will be available in 2.0.20
👍 3