https://kotlinlang.org logo
m

mike.holler

08/03/2021, 7:46 PM
I've been working with Kotlin/JS and Ktor's HTTP client, and although my tests pass in JVM and native, they fail for JavaScript. The reason why is cryptic. If it helps, I'm using the IR compiler and targeting the NodeJS runtime. Is there any way to get better error messages for something like this?
Copy code
Error_0: Fail to fetch
Error_0: Fail to fetch
	at _no_name_provided__246.invoke_1ti8hr(kotlin/multiplatform-sdk-end-to-end-tests-test.js:69724)
	at <global>.<unknown>(/home/mjholler/Git/multiplatform-sdk/build/js/packages/multiplatform-sdk-end-to-end-tests-test/kotlin/multiplatform-sdk-end-to-end-tests-test.js:69752)
	at <global>.processTicksAndRejections(internal/process/task_queues.js:93)
b

Big Chungus

08/03/2021, 8:56 PM
Few things might help: • temporarily switch to legacy backend to get proper stack traces and sourceMaps • Try gradle build scan (I find that it sometimes unearths extra details) • Check out your tests report in
build/reports
, which might have some logs not present in console • Shower your code with
println()
to pinpoint crash-site
Also I suspect you might be using GlobalScope to generate promises on js. If so, replace that with CoroutineScope(EptyCoroutineContext()) to see if it helps.
t

turansky

08/03/2021, 10:33 PM
Why
CoroutineScope(EptyCoroutineContext())
is better than
GlobalScope
?
b

Big Chungus

08/03/2021, 10:48 PM
GlobalScope is delicate api and can lead to unpredictable behaviour (programs not exiting due to hanging jobs on the GlobalScope and so on...). Constructung your one single-use coroutine scope will ensure that it can be freed up by GC when it's no longer needed (all promise handlers complete).
But that's just my understanding of it. Not pretending to be an expert or anything, just sharing my own observations of this.
I strongly recommend you do your own research on this sublect, but trust me on this - GlobalScope should be avoided where possible.
m

mike.holler

08/04/2021, 12:20 PM
Legacy backend helped. I am amazed they released a new compiler without debug support or source mapping. Scopes is a mess on the US side - but that's another story. Thanks for the suggestions!
b

Big Chungus

08/04/2021, 12:23 PM
Well IR for js is not released yet (you need to enable it explicitly, the default is still legacy)
20 Views