[FE] Add detailed report to possible failures in ComponentArrayOwner.registerComponent
This commit is contained in:
committed by
Space Team
parent
4beb55179b
commit
890418f6b7
@@ -16,11 +16,34 @@ abstract class ComponentArrayOwner<K : Any, V : Any> : AbstractArrayMapOwner<K,
|
|||||||
ArrayMapImpl()
|
ArrayMapImpl()
|
||||||
|
|
||||||
final override fun registerComponent(tClass: KClass<out K>, value: V) {
|
final override fun registerComponent(tClass: KClass<out K>, value: V) {
|
||||||
arrayMap[typeRegistry.getId(tClass)] = value
|
val id = typeRegistry.getId(tClass)
|
||||||
|
try {
|
||||||
|
arrayMap[id] = value
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw RuntimeException(createDiagnosticMessage(id, tClass), e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected operator fun get(key: KClass<out K>): V {
|
protected operator fun get(key: KClass<out K>): V {
|
||||||
val id = typeRegistry.getId(key)
|
val id = typeRegistry.getId(key)
|
||||||
return arrayMap[id] ?: error("No '$key'($id) component in array: $this")
|
return arrayMap[id] ?: error("No '$key'($id) component in array: $this")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createDiagnosticMessage(id: Int, tClass: KClass<*>): String = buildString {
|
||||||
|
appendLine("Error occurred during registration of component in array")
|
||||||
|
appendLine("Currently registered")
|
||||||
|
appendLine(" $id: $tClass")
|
||||||
|
appendLine("Registrar:")
|
||||||
|
for ((kClass, x) in typeRegistry.allValuesThreadUnsafeForRendering()) {
|
||||||
|
appendLine(" $x: $kClass")
|
||||||
|
}
|
||||||
|
appendLine("Array map:")
|
||||||
|
for (i in 0 until arrayMap.size) {
|
||||||
|
var element: Any? = arrayMap[i]
|
||||||
|
if (element != null) {
|
||||||
|
element = element::class
|
||||||
|
}
|
||||||
|
appendLine(" $i: $element")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user