diff --git a/backend/mirai-console/src/internal/util/CommonUtils.kt b/backend/mirai-console/src/internal/util/CommonUtils.kt index aca7b0d7d..a28170631 100644 --- a/backend/mirai-console/src/internal/util/CommonUtils.kt +++ b/backend/mirai-console/src/internal/util/CommonUtils.kt @@ -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 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()) +} \ No newline at end of file