mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix #139, rethrow exceptions caught in JvmPluginInternal.onEnable
This commit is contained in:
parent
3001de5834
commit
2ea86b377a
@ -143,14 +143,15 @@ internal val debuggingLogger1 by lazy {
|
||||
DefaultLogger("debug").withSwitch(true)
|
||||
}
|
||||
|
||||
internal inline fun <R> MiraiLogger.runCatchingLog(message: String? = null, block: () -> R): R? {
|
||||
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
|
||||
internal inline fun <R> MiraiLogger.runCatchingLog(message: String? = null, block: () -> R): Result<R> {
|
||||
return kotlin.runCatching {
|
||||
block()
|
||||
}.onFailure {
|
||||
if (message != null) {
|
||||
error(message, it)
|
||||
} else error(it)
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
@ -36,7 +36,8 @@ internal object JarPluginLoaderImpl :
|
||||
override val configStorage: PluginDataStorage
|
||||
get() = MiraiConsoleImplementationBridge.configStorageForJarPluginLoader
|
||||
|
||||
private val logger: MiraiLogger = MiraiConsole.createLogger(JarPluginLoader::class.simpleName!!)
|
||||
@JvmStatic
|
||||
internal val logger: MiraiLogger = MiraiConsole.createLogger(JarPluginLoader::class.simpleName!!)
|
||||
|
||||
override val dataStorage: PluginDataStorage
|
||||
get() = MiraiConsoleImplementationBridge.dataStorageForJarPluginLoader
|
||||
|
@ -13,6 +13,7 @@ import kotlinx.atomicfu.AtomicLong
|
||||
import kotlinx.atomicfu.locks.withLock
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.data.runCatchingLog
|
||||
import net.mamoe.mirai.console.internal.data.mkdir
|
||||
import net.mamoe.mirai.console.plugin.Plugin
|
||||
import net.mamoe.mirai.console.plugin.PluginManager
|
||||
@ -43,9 +44,11 @@ internal abstract class JvmPluginInternal(
|
||||
|
||||
// region JvmPlugin
|
||||
final override val logger: MiraiLogger by lazy {
|
||||
MiraiConsole.createLogger(
|
||||
"Plugin ${this.description.name}"
|
||||
)
|
||||
JarPluginLoaderImpl.logger.runCatchingLog {
|
||||
MiraiConsole.createLogger(
|
||||
"Plugin ${this.description.name}"
|
||||
)
|
||||
}.getOrThrow()
|
||||
}
|
||||
|
||||
private var firstRun = true
|
||||
@ -97,6 +100,7 @@ internal abstract class JvmPluginInternal(
|
||||
},
|
||||
onFailure = {
|
||||
cancel(CancellationException("Exception while enabling plugin", it))
|
||||
logger.error(it)
|
||||
return false
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user