Throw NoSuchComponentException with full details in CombinedComponentStorage.get

This commit is contained in:
Him188 2021-06-16 01:52:27 +08:00
parent 9933fab4c5
commit e6119e6301

View File

@ -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? {