diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt index 9e2960aa2c..fafd3a6947 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt +++ b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt @@ -128,16 +128,17 @@ internal abstract class JvmPluginInternal( val except = try { javaClass.getDeclaredAnnotation(ConsoleJvmPluginFuncCallbackStatusExcept.OnEnable::class.java) - }catch(e: Throwable){ + } catch (e: Throwable) { null } - + kotlin.runCatching { onEnable() }.fold( onSuccess = { if (except?.excepted == ConsoleJvmPluginFuncCallbackStatus.FAILED) { - val msg = "Test point '${javaClass.name}' assets failed but onEnable() invoked successfully" + val msg = + "Test point '${javaClass.name}' assets failed but onEnable() invoked successfully" cancel(msg) logger.error(msg) throw AssertionError(msg) @@ -205,7 +206,9 @@ internal abstract class JvmPluginInternal( .plus(parentCoroutineContext) .plus(CoroutineName("Plugin ${(this as AbstractJvmPlugin).dataHolderName}")) .plus( - SupervisorJob(parentCoroutineContext[Job] ?: JvmPluginLoader.coroutineContext[Job]!!) + SupervisorJob( + parentCoroutineContext[Job] ?: JvmPluginLoader.coroutineContext[Job]!! + ) ) .also { if (!MiraiConsole.isActive) return@also @@ -237,7 +240,10 @@ internal abstract class JvmPluginInternal( // endregion } -internal inline fun AtomicLong.updateWhen(condition: (Long) -> Boolean, update: (Long) -> Long): Boolean { +internal inline fun AtomicLong.updateWhen( + condition: (Long) -> Boolean, + update: (Long) -> Long +): Boolean { while (true) { val current = value if (condition(current)) { @@ -249,4 +255,5 @@ internal inline fun AtomicLong.updateWhen(condition: (Long) -> Boolean, update: } } -internal val Throwable.rootCauseOrSelf: Throwable get() = generateSequence(this) { it.cause }.lastOrNull() ?: this +internal val Throwable.rootCauseOrSelf: Throwable + get() = generateSequence(this) { it.cause }.lastOrNull() ?: this