Skip to content

Commit

Permalink
explain reason for exception, added resolution hint
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Nov 14, 2024
1 parent 3e6c9e3 commit a3acd0b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/core/IppAttribute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ data class IppAttribute<T>(val name: String, val tag: IppTag) : IppAttributeBuil
}

val value: T
get() =
if (attributeIs1setOf(name) == true) throw IppException("'$name' is registered as '1setOf', use 'values' instead")
else values.single()
get() = when {
attributeIs1setOf(name) == true -> throw IppException("'$name' is registered as '1setOf', use 'values' instead")
values.size > 1 -> throw IppException("'$name' has ${values.size} values, use 'values' instead")
else -> values.single()
}

@Suppress("UNCHECKED_CAST")
fun additionalValue(attribute: IppAttribute<*>) {
Expand Down

0 comments on commit a3acd0b

Please sign in to comment.