Ending the process while enabling the shutdownHook and without logging in causes UninitializedPropertyAccessException
Summary
Initializing Kord with the shutdown hook enabled causes a UninitializedPropertyAccessException when Kord was never logged in before.
Steps to reproduce
fun main() = runBlocking {
Kord(System.getenv("token"))
Unit
}
run the above and get the following error:
Exception in thread "Thread-14" kotlin.UninitializedPropertyAccessException: lateinit property socket has not been initialized
at com.gitlab.kordlib.gateway.DefaultGateway.detach(DefaultGateway.kt:176)
at com.gitlab.kordlib.core.cache.CachingGateway.detach(CachingGateway.kt)
at com.gitlab.kordlib.core.gateway.MasterGateway.detach(MasterGateway.kt:36)
at com.gitlab.kordlib.core.builder.kord.KordBuilder$build$3$1.invokeSuspend(KordBuilder.kt:201)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:271)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at com.gitlab.kordlib.core.builder.kord.KordBuilder$build$3.invoke(KordBuilder.kt:200)
at com.gitlab.kordlib.core.builder.kord.KordBuilder$build$3.invoke(KordBuilder.kt:51)
at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
Process finished with exit code 0
Expected Behavior
The DefaultGateway should not attempt to close its socket if it has not been initialized
Actual Behavior
The DefaultGateway does attempt this, and runs into a UninitializedPropertyAccessException.
Version
0.3.0-rc
Possible Fixes
DefaultGateway#detach(176) should check for the initialization of the socket property first.