m

    mike.holler

    1 year ago
    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?
    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)
    Big Chungus

    Big Chungus

    1 year ago
    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.
    turansky

    turansky

    1 year ago
    Why
    CoroutineScope(EptyCoroutineContext())
    is better than
    GlobalScope
    ?
    Big Chungus

    Big Chungus

    1 year ago
    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

    1 year ago
    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!
    Big Chungus

    Big Chungus

    1 year ago
    Well IR for js is not released yet (you need to enable it explicitly, the default is still legacy)