From e6119e6301e62ed974a4d84fb04e02f583cdfedb Mon Sep 17 00:00:00 2001 From: Him188 <Him188@mamoe.net> Date: Wed, 16 Jun 2021 01:52:27 +0800 Subject: [PATCH] Throw `NoSuchComponentException` with full details in `CombinedComponentStorage.get` --- .../kotlin/network/component/ComponentStorage.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/network/component/ComponentStorage.kt b/mirai-core/src/commonMain/kotlin/network/component/ComponentStorage.kt index 775fe8430..b0d727a25 100644 --- a/mirai-core/src/commonMain/kotlin/network/component/ComponentStorage.kt +++ b/mirai-core/src/commonMain/kotlin/network/component/ComponentStorage.kt @@ -53,7 +53,12 @@ private class CombinedComponentStorage( override val size: Int get() = main.size + fallback.size override fun <T : Any> get(key: ComponentKey<T>): T { - return main.getOrNull(key) ?: fallback.getOrNull(key) ?: main[key] // let `main` throw exception + return main.getOrNull(key) ?: fallback.getOrNull(key) ?: throw NoSuchComponentException(key, this) + .apply { + // + kotlin.runCatching { main[key] }.exceptionOrNull()?.let(::addSuppressed) + kotlin.runCatching { fallback[key] }.exceptionOrNull()?.let(::addSuppressed) + } } override fun <T : Any> getOrNull(key: ComponentKey<T>): T? {