Hi all, having a bit of trouble finding how to int...
# compose-web
r
Hi all, having a bit of trouble finding how to intercept any errors in the wasm Compose code; I just want to add some custom logging and display some html overlay. These two don't capture it for some reason:
Copy code
addEventListener("error", (event) => unhandledError(event, event.error));
addEventListener("unhandledrejection", (event) => unhandledError(event, event.reason));
Tried adding try/catch in the main function but also no luck. The crash does get logged in the console though, and Sentry JS does capture it as well.
a
If it's possible, could you please share what kind of errors appear in the console?
r
It's very weird to me. One time, if I use
chunked[6]
to force a crash, it does not catch it in my JS handler and the console log is very undescriptive. If I simply replace this with a listOf(1, 2, 3)[3], the crash is caught by the handler and also the console log has the entire stacktrace. The only difference that I see is that the
chunked
is a computed value from an observed state.
this consistently causes the crash to show the entire stack + the JS handler catches it. whereas using it on the items (which comes from the observed state) consistently does not show the stacktrace.
a
What version of KMP plugin do you use?
r
Using
0.8.3(242)-5
a
Are you sure it's the version of the multiplatform plugin?
r
@Artem Kobzar is it this one or am I looking at the wrong one?
a
Oh, sorry for misunderstanding. I'm about the Gradle plugin (in the project). You can find it either in build.gradle.kts:
Copy code
plugins {
  kotlin("multiplatform") version "..."
}
...
Or in the `lib.versions.toml`:
Copy code
[versions]
kotlin = "..."

[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
r
Ah okay, 2.0.21, but seeing the same with 2.1.0-RC2 as well, when accessing out of bounds list element the console does not print any stacktrace
❤️ 1
a
I will try to reproduce it on a "Hello, World" app, it's not reproduced, I will come back to you
👍 1
Btw, @Rok Oblak, is. it possible that you attach the handlers late, so the app is already failed before the handlers were added?
r
I think not as this happens upon a navigation into a screen (via a button), so at that time the handlers are long past attached.
a
I'm playing around the example: https://github.com/Kotlin/kotlin-wasm-browser-template/ With the attached patch, and seems like there it works.
👍 1