From 458bdd3ee4d5a8a3e60756dd25b12a02fb915afa Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 10 Sep 2025 15:29:55 +0600 Subject: [PATCH 1/4] start 28.0.2 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b02e6efae..f1f5313c5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 28.0.2 + ## 28.0.1 * `Version`: diff --git a/gradle.properties b/gradle.properties index df1d2e6ac2..91d2af3afa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ kotlin.incremental.js=true ksp.useKSP2=false library_group=dev.inmo -library_version=28.0.1 +library_version=28.0.2 From 4117288b215ea9afc84b9d8371d4d7dc7b7f6f79 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 10 Sep 2025 15:33:07 +0600 Subject: [PATCH 2/4] fix of #1001 --- CHANGELOG.md | 3 +++ .../tgbotapi/utils/CausedByCancellation.kt | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f5313c5a..0dd323bb0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 28.0.2 +* `Core`: + * Fix of [#1001](https://github.com/InsanusMokrassar/ktgbotapi/issues/1001) + ## 28.0.1 * `Version`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CausedByCancellation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CausedByCancellation.kt index 3b65f8071e..08c921dffc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CausedByCancellation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CausedByCancellation.kt @@ -2,6 +2,17 @@ package dev.inmo.tgbotapi.utils import kotlinx.coroutines.CancellationException +/** + * Traverses this throwable's cause chain to find a [CancellationException]. + * + * It walks through `this` and its `cause`s until the first [CancellationException] is encountered, + * and returns that exception. If no [CancellationException] is found in the chain, returns `null`. + * + * This is useful when you need to distinguish cancellations from other failures while handling errors. + * + * @receiver the root [Throwable] to inspect + * @return the first [CancellationException] found in the cause chain, or `null` if none present + */ fun Throwable.causedCancellationException(): CancellationException? { var current = this while (current !is CancellationException) { @@ -15,4 +26,10 @@ fun Throwable.causedCancellationException(): CancellationException? { return current } -fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() == null +/** + * Checks whether this throwable (or any of its causes) is a [CancellationException]. + * + * @receiver the [Throwable] to inspect + * @return `true` if a [CancellationException] is found in the cause chain, `false` otherwise + */ +fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() != null From da4cd527ec69ee604b480b77250ddc52fa2b9dff Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 10 Sep 2025 15:45:45 +0600 Subject: [PATCH 3/4] fix of #1002 --- CHANGELOG.md | 1 + .../tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt | 3 ++- .../inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd323bb0c..77f38fc49d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * `Core`: * Fix of [#1001](https://github.com/InsanusMokrassar/ktgbotapi/issues/1001) + * Fix of [#1002](https://github.com/InsanusMokrassar/ktgbotapi/issues/1002) ## 28.0.1 diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt index 38ae9a9d66..f6e7c7f14c 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourBuilders.kt @@ -87,6 +87,7 @@ suspend fun TelegramBot.buildBehaviourWithLongPolling( timeoutSeconds = timeoutSeconds, autoDisableWebhooks = autoDisableWebhooks, autoSkipTimeoutExceptions = autoSkipTimeoutExceptions, - mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis + mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis, + exceptionsHandler = defaultExceptionsHandler ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt index d2c683f09d..40ca65a261 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor.kt @@ -84,7 +84,7 @@ class DefaultKtorRequestsExecutor internal constructor( when (e) { is ClientRequestException -> { - val exceptionResult = runCatching { + val exceptionResult = runCatchingLogging(logger = Log) { val content = e.response.bodyAsText() val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content) newRequestException( From 9be5ebb036e7d7fe7472d4388d0dc7b37045c679 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 10 Sep 2025 15:58:43 +0600 Subject: [PATCH 4/4] refactor changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f38fc49d..aae5d69e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ ## 28.0.2 * `Core`: - * Fix of [#1001](https://github.com/InsanusMokrassar/ktgbotapi/issues/1001) - * Fix of [#1002](https://github.com/InsanusMokrassar/ktgbotapi/issues/1002) + * [#1001](https://github.com/InsanusMokrassar/ktgbotapi/issues/1001) - `[Bug] Invalid detection of isCausedByCancellation()` + * [#1002](https://github.com/InsanusMokrassar/ktgbotapi/issues/1002) - `Unable to handle UnauthorizedException with buildBehaviourWithLongPolling` ## 28.0.1