Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #900

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deployment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
Expand All @@ -49,7 +49,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ repositories {
mavenCentral()
}

kotlin {
compilerOptions {
allWarningsAsErrors = true
}
}

dependencies {
implementation(libs.bundles.pluginsForBuildSrc)
}
12 changes: 5 additions & 7 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ kotlin {
api(libs.kotlinx.coroutines.core)
api(libs.kotlinx.serialization.json)
api(libs.kotlinx.datetime)
api(libs.kotlin.logging)

api(libs.ktor.client.core)

compileOnly(projects.kspAnnotations)
Expand Down Expand Up @@ -52,15 +50,15 @@ internal const val BUILD_CONFIG_GENERATED_COMMIT_HASH: String = "<commit hash>"
internal const val BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH: String = "<short commit hash>"
*/
buildConfig {
packageName("dev.kord.common")
className("BuildConfigGenerated")
packageName = "dev.kord.common"
className = "BuildConfigGenerated"

useKotlinOutput {
topLevelConstants = true
internalVisibility = true
}

buildConfigField("String", "BUILD_CONFIG_GENERATED_LIBRARY_VERSION", "\"$libraryVersion\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_COMMIT_HASH", "\"$commitHash\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH", "\"$shortCommitHash\"")
buildConfigField("BUILD_CONFIG_GENERATED_LIBRARY_VERSION", libraryVersion)
buildConfigField("BUILD_CONFIG_GENERATED_COMMIT_HASH", commitHash)
buildConfigField("BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH", shortCommitHash)
}
1 change: 1 addition & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public final class dev/kord/core/KordKt {
public static final fun Kord (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun Kord$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun getKordLogger ()Lmu/KLogger;
public static final fun logCaughtThrowable (Ljava/lang/Throwable;)V
}

public abstract interface class dev/kord/core/KordObject {
Expand Down
10 changes: 10 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ kotlin {

api(libs.kord.cache.api)
api(libs.kord.cache.map)

implementation(libs.kotlin.logging)

// TODO remove when kordLogger is removed
implementation(libs.kotlin.logging.old)
}
}
jvmMain {
dependencies {
implementation(libs.slf4j.api)
}
}
jvmTest {
Expand Down
13 changes: 9 additions & 4 deletions core/src/commonMain/kotlin/Kord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,21 @@ import dev.kord.rest.builder.interaction.*
import dev.kord.rest.builder.user.CurrentUserModifyBuilder
import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.RestClient
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import mu.KLogger
import mu.KotlinLogging
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.channels.Channel as CoroutineChannel

public val kordLogger: KLogger = KotlinLogging.logger { }
@Deprecated("Use your own logger instead, this will be removed in the future.", level = DeprecationLevel.WARNING)
public val kordLogger: mu.KLogger = mu.KotlinLogging.logger { }

private val logger = KotlinLogging.logger { }

@PublishedApi
internal fun logCaughtThrowable(throwable: Throwable): Unit = logger.catching(throwable)


/**
Expand Down Expand Up @@ -634,6 +639,6 @@ public inline fun <reified T : Event> Kord.on(
): Job =
events.buffer(CoroutineChannel.UNLIMITED).filterIsInstance<T>()
.onEach { event ->
scope.launch { runCatching { consumer(event) }.onFailure { kordLogger.catching(it) } }
scope.launch { runCatching { consumer(event) }.onFailure(::logCaughtThrowable) }
}
.launchIn(scope)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.kord.core.gateway.handler
import dev.kord.common.annotation.KordPreview
import dev.kord.core.Kord
import dev.kord.core.gateway.ShardEvent
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import dev.kord.core.event.Event as CoreEvent

private val logger = KotlinLogging.logger { }
Expand Down
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/live/LiveKordEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dev.kord.core.entity.KordEntity
import dev.kord.core.event.Event
import dev.kord.core.event.message.MessageUpdateEvent
import dev.kord.core.event.message.ReactionAddEvent
import dev.kord.core.kordLogger
import dev.kord.core.logCaughtThrowable
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
Expand Down Expand Up @@ -53,5 +53,5 @@ public inline fun <reified T : Event> LiveKordEntity.on(
noinline consumer: suspend (T) -> Unit
): Job =
events.buffer(Channel.UNLIMITED).filterIsInstance<T>().onEach {
runCatching { consumer(it) }.onFailure { kordLogger.catching(it) }
}.catch { kordLogger.catching(it) }.launchIn(scope)
runCatching { consumer(it) }.onFailure(::logCaughtThrowable)
}.catch { logCaughtThrowable(it) }.launchIn(scope)
1 change: 1 addition & 0 deletions gateway/api/gateway.api
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ public final class dev/kord/gateway/GatewayConfigurationBuilder {
public final class dev/kord/gateway/GatewayKt {
public static final fun editPresence (Ldev/kord/gateway/Gateway;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun getGatewayOnLogger ()Lmu/KLogger;
public static final fun logCaughtThrowable (Ljava/lang/Throwable;)V
public static final fun requestGuildMembers (Ldev/kord/gateway/Gateway;Ldev/kord/common/entity/Snowflake;Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/flow/Flow;
public static final fun requestGuildMembers (Ldev/kord/gateway/Gateway;Ldev/kord/gateway/RequestGuildMembers;)Lkotlinx/coroutines/flow/Flow;
public static synthetic fun requestGuildMembers$default (Ldev/kord/gateway/Gateway;Ldev/kord/common/entity/Snowflake;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow;
Expand Down
10 changes: 10 additions & 0 deletions gateway/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ kotlin {
api(libs.bundles.ktor.client.serialization)
api(libs.ktor.client.websockets)

implementation(libs.kotlin.logging)

// TODO remove when gatewayOnLogger and mu.KLogger.error() are removed
implementation(libs.kotlin.logging.old)

compileOnly(projects.kspAnnotations)
}
}
jvmMain {
dependencies {
implementation(libs.slf4j.api)
}
}
jsMain {
dependencies {
implementation(libs.kotlin.node)
Expand Down
10 changes: 5 additions & 5 deletions gateway/src/commonMain/kotlin/DefaultGateway.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dev.kord.gateway.GatewayCloseCode.*
import dev.kord.gateway.handler.*
import dev.kord.gateway.ratelimit.IdentifyRateLimiter
import dev.kord.gateway.retry.Retry
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.*
import io.ktor.client.plugins.websocket.*
import io.ktor.client.request.*
Expand All @@ -22,7 +23,6 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -119,7 +119,7 @@ public class DefaultGateway(private val data: DefaultGatewayData) : Gateway {
*/
inflater = Inflater()
} catch (exception: Exception) {
defaultGatewayLogger.error(exception)
defaultGatewayLogger.error(exception) { "" }
if (exception.isTimeout()) {
data.eventFlow.emit(Close.Timeout)
}
Expand All @@ -131,15 +131,15 @@ public class DefaultGateway(private val data: DefaultGatewayData) : Gateway {
try {
readSocket()
} catch (exception: Exception) {
defaultGatewayLogger.error(exception)
defaultGatewayLogger.error(exception) { "" }
}

defaultGatewayLogger.trace { "gateway connection closing" }

try {
handleClose()
} catch (exception: Exception) {
defaultGatewayLogger.error(exception)
defaultGatewayLogger.error(exception) { "" }
}

defaultGatewayLogger.trace { "handled gateway connection closed" }
Expand Down Expand Up @@ -189,7 +189,7 @@ public class DefaultGateway(private val data: DefaultGatewayData) : Gateway {
val event = jsonParser.decodeFromString(Event.DeserializationStrategy, json) ?: return
data.eventFlow.emit(event)
} catch (exception: Exception) {
defaultGatewayLogger.error(exception)
defaultGatewayLogger.error(exception) { "" }
}

}
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/commonMain/kotlin/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.kord.common.entity.*
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalSnowflake
import dev.kord.common.serialization.DurationInSeconds
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.datetime.Instant
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
Expand All @@ -21,7 +22,6 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import mu.KotlinLogging
import kotlin.jvm.JvmField
import kotlinx.serialization.DeserializationStrategy as KDeserializationStrategy

Expand Down
16 changes: 11 additions & 5 deletions gateway/src/commonMain/kotlin/Gateway.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.Optional
import dev.kord.gateway.builder.PresenceBuilder
import dev.kord.gateway.builder.RequestGuildMembersBuilder
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import mu.KLogger
import mu.KotlinLogging
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -140,11 +139,18 @@ public suspend inline fun Gateway.start(token: String, config: GatewayConfigurat
start(builder.build())
}

@Suppress("unused")
@Deprecated("Binary compatibility, remove after deprecation cycle.", level = DeprecationLevel.WARNING)
@PublishedApi
internal val gatewayOnLogger: mu.KLogger = mu.KotlinLogging.logger("Gateway.on")

/**
* Logger used to report throwables caught in [Gateway.on].
* Logger used to report [Throwable]s caught in [Gateway.on].
*/
private val logger = KotlinLogging.logger("Gateway.on")

@PublishedApi
internal val gatewayOnLogger: KLogger = KotlinLogging.logger("Gateway.on")
internal fun logCaughtThrowable(throwable: Throwable): Unit = logger.catching(throwable)

/**
* Convenience method that will invoke the [consumer] on every event [T] created by [Gateway.events].
Expand All @@ -162,7 +168,7 @@ public inline fun <reified T : Event> Gateway.on(
crossinline consumer: suspend T.() -> Unit
): Job {
return this.events.buffer(Channel.UNLIMITED).filterIsInstance<T>().onEach {
launch { it.runCatching { it.consumer() }.onFailure(gatewayOnLogger::error) }
launch { it.runCatching { it.consumer() }.onFailure(::logCaughtThrowable) }
}.launchIn(scope)
}

Expand Down
4 changes: 2 additions & 2 deletions gateway/src/commonMain/kotlin/Ticker.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package dev.kord.gateway

import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import mu.KotlinLogging
import kotlin.coroutines.CoroutineContext

private val logger = KotlinLogging.logger { }
Expand All @@ -33,7 +33,7 @@ public class Ticker(private val dispatcher: CoroutineDispatcher = Dispatchers.De
try {
block()
} catch (exception: Exception) {
logger.error(exception)
logger.error(exception) { "" }
}
}.launchIn(this)
}
Expand Down
2 changes: 2 additions & 0 deletions gateway/src/commonMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ package dev.kord.gateway

import mu.KLogger

@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Binary compatibility, remove after deprecation cycle.", level = DeprecationLevel.WARNING)
@PublishedApi
internal fun KLogger.error(throwable: Throwable): Unit = error(throwable) { "" }
2 changes: 1 addition & 1 deletion gateway/src/commonMain/kotlin/handler/Handler.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package dev.kord.gateway.handler

import dev.kord.gateway.Event
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import mu.KotlinLogging
import kotlin.coroutines.CoroutineContext

private val logger = KotlinLogging.logger("[Handler]")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kord.gateway.ratelimit

import dev.kord.gateway.*
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.getAndUpdate
import kotlinx.atomicfu.loop
Expand All @@ -11,7 +12,6 @@ import kotlinx.coroutines.channels.onSuccess
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.selects.onTimeout
import kotlinx.coroutines.selects.select
import mu.KotlinLogging
import kotlin.jvm.JvmField
import kotlin.time.Duration.Companion.seconds

Expand Down
2 changes: 1 addition & 1 deletion gateway/src/commonMain/kotlin/retry/LinearRetry.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.kord.gateway.retry

import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.update
import kotlinx.coroutines.delay
import mu.KotlinLogging
import kotlin.time.Duration
import kotlin.time.times

Expand Down
Loading