Add assertionError

This commit is contained in:
Him188 2020-11-17 08:36:49 +08:00
parent 6f3e59856e
commit fb82d8236d

View File

@ -7,12 +7,14 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:JvmName("CommonUtils")
@file:JvmName("CommonUtils") // maintain binary compatibility
package net.mamoe.mirai.console.internal.util
import io.github.karlatemp.caller.StackFrame
import net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
internal inline fun <reified E : Throwable, R> runIgnoreException(block: () -> R): R? {
try {
@ -38,3 +40,9 @@ internal fun StackFrame.findLoader(): ClassLoader? {
BuiltInJvmPluginLoaderImpl.classLoaders.firstOrNull { it.findClass(className, true) != null }
}.getOrNull()
}
@PublishedApi
internal inline fun assertionError(message: () -> String): Nothing {
contract { callsInPlace(message, InvocationKind.EXACTLY_ONCE) }
throw AssertionError(message())
}