Ignore CancellationException on stop

This commit is contained in:
Him188 2020-09-10 09:04:06 +08:00
parent 3c64b99553
commit 42a4c844e1

View File

@ -9,10 +9,7 @@
package net.mamoe.mirai.console.command package net.mamoe.mirai.console.command
import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.*
import kotlinx.coroutines.cancel
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
@ -122,8 +119,9 @@ public object BuiltInCommands {
ignoreException<EventCancelledException> { sendMessage("mirai-console stopped successfully.") } ignoreException<EventCancelledException> { sendMessage("mirai-console stopped successfully.") }
}, },
onFailure = { onFailure = {
if (it is CancellationException) return@fold
@OptIn(ConsoleInternalAPI::class) @OptIn(ConsoleInternalAPI::class)
MiraiConsole.mainLogger.error(it) MiraiConsole.mainLogger.error("Exception in stop", it)
ignoreException<EventCancelledException> { ignoreException<EventCancelledException> {
sendMessage( sendMessage(
it.localizedMessage ?: it.message ?: it.toString() it.localizedMessage ?: it.message ?: it.toString()