Skip to content

ClassCastException is thrown when building an ApolloClient using a builder in KotlinJS #5801

Closed
@AngeloFilaseta

Description

@AngeloFilaseta

Version

4.0.0-beta.5

Summary

When calling the build() method on a Builder offered by ApolloClient on KotlinJS i get a ClassCastException. It is not really easy for me to debug the error, since the it refer to pieces of code that were generated.

The problem does not appear on the JVM platform. If i use the 3.8.3 version everything work perfectly as I would expect.

Steps to reproduce the behavior

I use this configuration in order create my javascript binaries in my build.gradle.kts

  js(IR) {
      browser {
          binaries.executable()
      }
  }

and use the .js output offered by the task jsBrowserDevelopmentWebpack. The problem appears when using the production task too.

The code that causes problem in my case is the following. In this case we fall inside the catch block:

try {
  ApolloClient.Builder()
    .serverUrl("http://0.0.0.0:1313/graphql")
    .build()
} catch (e: ClassCastException) {
  console.error(e.cause)
  console.error(e.message)
  console.log(e.printStackTrace())
}

Both the cause and the message are undefined,
As far as I understood it is not the serverUrl parameter that causes the error.

Logs

throwableExtensions.kt:25 ClassCastException
    at THROW_CCE (webpack-internal:///./kotlin/kotlin-kotlin-stdlib.js:5844:11)
    at WindowDispatcher.get_0 [as get_y2st91_k$] (webpack-internal:///./kotlin/kotlin-kotlin-stdlib.js:551:51)
    at protoOf.get_y2st91_k$ (webpack-internal:///./kotlin/kotlin-kotlin-stdlib.js:19369:46)
    at CoroutineContext$plus$lambda (webpack-internal:///./kotlin/kotlin-kotlin-stdlib.js:19208:33)
    at CoroutineName.fold [as fold_j2vaxd_k$] (webpack-internal:///./kotlin/kotlin-kotlin-stdlib.js:530:12)
    at CombinedContext.plus [as plus_s13ygv_k$] (webpack-internal:///./kotlin/kotlin-kotlin-stdlib.js:515:21)
    at eval (webpack-internal:///./kotlin/ktor-ktor-client-core.js:1835:83)
    at protoOf.get_value_j01efc_k$ (webpack-internal:///./kotlin/kotlin-kotlin-stdlib.js:24692:56)
    at protoOf.get_coroutineContext_115oqo_k$ (webpack-internal:///./kotlin/ktor-ktor-client-core.js:1852:19)
    at HttpClient (webpack-internal:///./kotlin/ktor-ktor-client-core.js:626:42)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions