mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +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)
|
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 {
|
return kotlin.runCatching {
|
||||||
block()
|
block()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
error(message, it)
|
error(message, it)
|
||||||
} else error(it)
|
} else error(it)
|
||||||
}.getOrNull()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
@ -36,7 +36,8 @@ internal object JarPluginLoaderImpl :
|
|||||||
override val configStorage: PluginDataStorage
|
override val configStorage: PluginDataStorage
|
||||||
get() = MiraiConsoleImplementationBridge.configStorageForJarPluginLoader
|
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
|
override val dataStorage: PluginDataStorage
|
||||||
get() = MiraiConsoleImplementationBridge.dataStorageForJarPluginLoader
|
get() = MiraiConsoleImplementationBridge.dataStorageForJarPluginLoader
|
||||||
|
@ -13,6 +13,7 @@ import kotlinx.atomicfu.AtomicLong
|
|||||||
import kotlinx.atomicfu.locks.withLock
|
import kotlinx.atomicfu.locks.withLock
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import net.mamoe.mirai.console.MiraiConsole
|
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.internal.data.mkdir
|
||||||
import net.mamoe.mirai.console.plugin.Plugin
|
import net.mamoe.mirai.console.plugin.Plugin
|
||||||
import net.mamoe.mirai.console.plugin.PluginManager
|
import net.mamoe.mirai.console.plugin.PluginManager
|
||||||
@ -43,9 +44,11 @@ internal abstract class JvmPluginInternal(
|
|||||||
|
|
||||||
// region JvmPlugin
|
// region JvmPlugin
|
||||||
final override val logger: MiraiLogger by lazy {
|
final override val logger: MiraiLogger by lazy {
|
||||||
MiraiConsole.createLogger(
|
JarPluginLoaderImpl.logger.runCatchingLog {
|
||||||
"Plugin ${this.description.name}"
|
MiraiConsole.createLogger(
|
||||||
)
|
"Plugin ${this.description.name}"
|
||||||
|
)
|
||||||
|
}.getOrThrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var firstRun = true
|
private var firstRun = true
|
||||||
@ -97,6 +100,7 @@ internal abstract class JvmPluginInternal(
|
|||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
cancel(CancellationException("Exception while enabling plugin", it))
|
cancel(CancellationException("Exception while enabling plugin", it))
|
||||||
|
logger.error(it)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user