supabase-community / supabase-kt

A Kotlin Multiplatform Client for Supabase.
https://supabase.com/docs/reference/kotlin/introduction
MIT License
415 stars 37 forks source link

[Question]: Does this work with KMP JVM (Ktor Server)? #702

Closed basurahan closed 2 months ago

basurahan commented 2 months ago

General info

What is your question?

I am building api server using KMP Ktor. When I am calling createSupabaseClient i get an exception ExceptionInInitializerError when I remove that call to createSupabaseClient it works fine so I know its createSupabaseClient that producing it

Relevant log output (optional)

Info: (Supabase-Core) SupabaseClient created! Please report any bugs you find.
2024-08-31 15:02:25.313 [eventLoopGroupProxy-4-1] TRACE i.k.s.p.statuspages.StatusPages - Call /api/v1/register failed with cause java.lang.ExceptionInInitializerError
2024-08-31 15:02:25.373 [eventLoopGroupProxy-4-1] TRACE i.k.s.p.statuspages.StatusPages - Executing (io.ktor.server.application.ApplicationCall, kotlin.Throwable) -> kotlin.Unit for exception java.lang.ExceptionInInitializerError for call /api/v1/register
jan-tennert commented 2 months ago

Did you take a look at this docs section?

basurahan commented 2 months ago

Yes I followed the docs

Screenshot 2024-08-31 at 4 33 34 PM

as you can see I am only using the supbase client on server module. So I dont need it on other platforms just the JVM Ktor Server to use as a api server

jan-tennert commented 2 months ago

Can you post the full exception?

basurahan commented 2 months ago

The full exception is posted in the Relevant log output. Here is a screenshot as a proof

Screenshot 2024-08-31 at 4 46 55 PM
jan-tennert commented 2 months ago

That is not the full stacktrace. Try to try catch it.

basurahan commented 2 months ago
Info: (Supabase-Core) SupabaseClient created! Please report any bugs you find.
2024-08-31 17:15:58.646 [eventLoopGroupProxy-4-1] ERROR ktor.application - Exception of type class java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError: null
        at io.github.jan.supabase.network.KtorSupabaseHttpClient.<init>(KtorSupabaseHttpClient.kt:46)
        at io.github.jan.supabase.SupabaseClientImpl.<init>(SupabaseClient.kt:115)
        at io.github.jan.supabase.SupabaseClientBuilder.build(SupabaseClientBuilder.kt:103)
        at link.limecode.reddit.lite.routes.authentication.AuthenticaionRoutesKt$authenticationRoutes$1.invokeSuspend(AuthenticaionRoutes.kt:51)
        at link.limecode.reddit.lite.routes.authentication.AuthenticaionRoutesKt$authenticationRoutes$1.invoke(AuthenticaionRoutes.kt)
        at link.limecode.reddit.lite.routes.authentication.AuthenticaionRoutesKt$authenticationRoutes$1.invoke(AuthenticaionRoutes.kt)
        at io.ktor.server.routing.Route$buildPipeline$1$1.invokeSuspend(Route.kt:116)
        at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
        at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:131)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:89)
        at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:109)
        at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
        at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
        at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
        at io.ktor.server.routing.Routing.executeResult(Routing.kt:190)
        at io.ktor.server.routing.Routing.interceptor(Routing.kt:64)
        at io.ktor.server.routing.Routing$Plugin$install$1.invokeSuspend(Routing.kt:140)
        at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
        at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:131)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:89)
        at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invokeSuspend(BaseApplicationEngine.kt:124)
        at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
        at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:131)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:89)
        at io.ktor.server.application.hooks.CallFailed$install$1$1.invokeSuspend(CommonHooks.kt:45)
        at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
        at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:61)
        at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:261)
        at io.ktor.server.application.hooks.CallFailed$install$1.invokeSuspend(CommonHooks.kt:44)
        at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
        at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:131)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:89)
        at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:109)
        at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invokeSuspend(DefaultEnginePipeline.kt:123)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:131)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:89)
        at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:109)
        at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invokeSuspend(NettyApplicationCallHandler.kt:140)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:27)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:90)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
        at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
        at io.ktor.server.netty.NettyApplicationCallHandler.handleRequest(NettyApplicationCallHandler.kt:41)
        at io.ktor.server.netty.NettyApplicationCallHandler.channelRead(NettyApplicationCallHandler.kt:33)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
        at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:61)
        at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:425)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda$1$lambda$0(NettyApplicationEngine.kt:296)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.IllegalStateException: Failed to find HTTP client engine implementation in the classpath: consider adding client engine dependency. See https://ktor.io/docs/http-client-engines.html
        at io.ktor.client.HttpClientJvmKt.<clinit>(HttpClientJvm.kt:43)
        ... 78 common frames omitted
2024-08-31 17:15:58.715 [eventLoopGroupProxy-4-1] TRACE i.k.s.p.statuspages.StatusPages - No status code found for call: /api/v1/register
basurahan commented 2 months ago

Seems like http client is missing but as we can see I already added CIO @jan-tennert

basurahan commented 2 months ago

Its now working I restarted fleet 🙈