Do not wrap exception into ISE on reaching max attempts

This commit is contained in:
Him188 2021-06-16 17:26:57 +08:00
parent a38f24cbe5
commit fc477e0122
3 changed files with 16 additions and 4 deletions

View File

@ -76,10 +76,7 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
private tailrec suspend fun runImpl(): H {
if (attempted >= maxAttempts) {
throw IllegalStateException(
"Failed to resume instance. Maximum attempts reached.",
exceptionCollector.getLast()
)
throw exceptionCollector.getLast() ?: MaxAttemptsReachedException(null)
}
yield() // Avoid endless recursion.
val current = getCurrentInstanceOrNull()

View File

@ -0,0 +1,14 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.internal.network.handler.selector
internal data class MaxAttemptsReachedException(
override val cause: Throwable?
) : IllegalStateException("Failed to resume instance. Maximum attempts reached.")

View File

@ -40,6 +40,7 @@ internal interface NetworkHandlerSelector<H : NetworkHandler> {
* Returned [H] can be in [NetworkHandler.State.OK] only (but it may happen that the state changed just after returning from this function).
*
* This function may throw exceptions, which would be propagated to the original caller of [SelectorNetworkHandler.resumeConnection].
* @throws MaxAttemptsReachedException
*/
suspend fun awaitResumeInstance(): H
}