Hello everyone. I've been playing around with kotl...
# javascript
e
Hello everyone. I've been playing around with kotlin in browser and faced such a thing, that kotlin-js does not provide exception stacktrace. It seems a little bit strange and uncomfortable, but I guess it is because there is no standardized stacktrace feature in javascript. Haven't I missed something? May be anyone can hint some library that expose stacktrace as an extension? I didn't found any. 😞
r
Hi, which browser do you use? Probably stacktrace is turned off for some reason
e
Latest Firefox. I mean, I can not get trace by exception object, only seen it in browser console, but in terms of produced Javascript code.
r
I think from kotlin code stacktrace could be accessed via
ex.asDynamic().stack
where
ex
is exception object
e
Yes, using
ex.asDynamic().stack
can be kind of usable to have at least some stacktrace, but as I said, it contains JS code trace and needs to be mapped back to kotlin one, unless you do not prefer to analyze code generated by kotlinjs.
Also I've made a little demo of problem with in-browser kotlin exception logging and even workaround for it, but it is (a) translation level and (b) not recommended by MDN documenation, so not very usable outside of demo. See https://repl.it/@mrEDitor/kotlinjs-exceptions-inheritance, hope it self-descriptive enough.
s
Source maps in stacktraces supported only in chrome and nodejs, and should work out of box. We are using https://www.npmjs.com/package/source-map-support for that. It uses the
.js.map
files to replace the paths and line numbers of source-mapped files with their original paths and line numbers.
Firefox lacks of stractraces api (v8 has https://v8.dev/docs/stack-trace-api), so there is no way to support it in Firefox.
Could you tell more about your demo? What does it do?
e
There is
main.kt
file in it, it just throws
class MyThrowable(s: String) : Throwable(s)
exception, then catches it, logs
stack
property and re-throws it out of
main()
.