Add variable description to VariableMutationException

commit_hash:db7d3a48789b7f9a2f20953be46f67255c900ed9
This commit is contained in:
i-ts
2026-02-12 13:41:36 +03:00
parent a35406a23f
commit c5cea21a9a
@@ -304,10 +304,27 @@ sealed class Variable {
this is DictVariable && from is DictVariable -> this.value = from.value
this is ArrayVariable && from is ArrayVariable -> this.value = from.value
this is PropertyVariable && from is PropertyVariable -> this.value = from.value
else -> throw VariableMutationException("Setting value to $this from $from not supported!")
else -> throw VariableMutationException(
"Setting value to ${describeVariable(this)} from ${describeVariable(from)} not supported!")
}
}
private fun describeVariable(variable: Variable): String {
val type = when (variable) {
is ArrayVariable -> "ArrayVariable"
is BooleanVariable -> "BooleanVariable"
is ColorVariable -> "ColorVariable"
is DictVariable -> "DictVariable"
is DoubleVariable -> "DoubleVariable"
is IntegerVariable -> "IntegerVariable"
is PropertyVariable -> "PropertyVariable"
is StringVariable -> "StringVariable"
is UrlVariable -> "UrlVariable"
}
return "$type(name: '${variable.name}')"
}
@InternalApi
@MainThread
@Throws(VariableMutationException::class)
@@ -325,7 +342,7 @@ sealed class Variable {
is PropertyVariable -> value = newValue
}
} catch (_: ClassCastException) {
throw VariableMutationException("Unable to set value with type ${newValue.javaClass} to $this")
throw VariableMutationException("Unable to set value with type ${newValue.javaClass} to ${describeVariable(this)}")
}
}