mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-31 20:02:27 +08:00
Improve logs on event exception
This commit is contained in:
parent
70dc0a4da6
commit
c7dfef9ad5
@ -18,7 +18,6 @@ import net.mamoe.mirai.utils.MiraiLogger
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.coroutines.coroutineContext
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
||||||
@ -49,14 +48,16 @@ internal class Handler<in E : Event> internal constructor(
|
|||||||
withContext(subscriberContext) { handler.invoke(event) }.also { if (it == ListeningStatus.STOPPED) this.complete() }
|
withContext(subscriberContext) { handler.invoke(event) }.also { if (it == ListeningStatus.STOPPED) this.complete() }
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
subscriberContext[CoroutineExceptionHandler]?.handleException(subscriberContext, e)
|
subscriberContext[CoroutineExceptionHandler]?.handleException(subscriberContext, e)
|
||||||
?: coroutineContext[CoroutineExceptionHandler]?.handleException(subscriberContext, e)
|
?: currentCoroutineContext()[CoroutineExceptionHandler]?.handleException(subscriberContext, e)
|
||||||
?: kotlin.run {
|
?: kotlin.run {
|
||||||
@Suppress("DEPRECATION")
|
val logger = if (event is BotEvent) event.bot.logger else MiraiLogger.TopLevel
|
||||||
(if (event is BotEvent) event.bot.logger else MiraiLogger.TopLevel)
|
val subscriberName = subscriberContext[CoroutineName]?.name ?: "<unnamed>"
|
||||||
.warning(
|
val broadcasterName = currentCoroutineContext()[CoroutineName]?.name ?: "<unnamed>"
|
||||||
"""Event processing: An exception occurred but no CoroutineExceptionHandler found,
|
val message =
|
||||||
either in coroutineContext from Handler job, or in subscriberContext""".trimIndent(), e
|
"An exception occurred when processing event. " +
|
||||||
)
|
"Subscriber scope: '$subscriberName'. " +
|
||||||
|
"Broadcaster scope: '$broadcasterName'"
|
||||||
|
logger.warning(message, e)
|
||||||
}
|
}
|
||||||
// this.complete() // do not `completeExceptionally`, otherwise parentJob will fai`l.
|
// this.complete() // do not `completeExceptionally`, otherwise parentJob will fai`l.
|
||||||
// ListeningStatus.STOPPED
|
// ListeningStatus.STOPPED
|
||||||
|
Loading…
Reference in New Issue
Block a user