Report validation error for duplicate action names#1528
Conversation
This commit ensures that actions names only occur once, and reports a validation error otherwise. Closes: embabelgh-1304 Signed-off-by: Arjen Poutsma <poutsma@mac.com>
igordayen
left a comment
There was a problem hiding this comment.
minor comment to consider in future. looks good
| ) | ||
| } | ||
|
|
||
| // Check for duplicate action names |
There was a problem hiding this comment.
at some point for documentation purposes perhaps collect all error codes / maintain enum for ValidationError.code:
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt:import com.embabel.common.core.validation.ValidationError
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt: val errors = mutableListOf<ValidationError>()
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt: ): ValidationError =
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/GoapPathToCompletionValidator.kt: ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt:import com.embabel.common.core.validation.ValidationError
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt: val error = ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt: val errors = mutableListOf<ValidationError>()
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt: ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt: ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt: ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/DefaultAgentStructureValidator.kt: ValidationError(
./embabel-agent-api/src/main/kotlin/com/embabel/agent/core/hitl/FormBindingRequest.kt:interface ValidationError
./embabel-agent-api/src/main/kotlin/com/embabel/agent/core/hitl/FormBindingRequest.kt: val validationErrors: List<ValidationError> = emptyList(),
./embabel-agent-api/src/main/kotlin/com/embabel/common/core/validation/ValidationResult.kt: val errors: List<ValidationError>,
./embabel-agent-api/src/main/kotlin/com/embabel/common/core/validation/ValidationError.kt:data class ValidationError @JvmOverloads constructor(
alexheifetz
left a comment
There was a problem hiding this comment.
Very nice fix — groupBy { it.name }.filter { it.value.size > 1 } is the right idiom and the validator is the right layer.
Two minor things:
- Agreeing with @igordayen on typed error codes — the raw string in the test assertion is a silent typo risk.
- The error message could include the declaring class of each duplicate so the developer knows where to look, not just that a collision exists.
Sounds good, I will create a follow-up issue for that.
The action name is used in the message, and will be the fully qualified method name when using annotations. For instance, for the unit test it's |
|
I have created #1533 to collect all validation error codes. |
This PR ensures that actions names only occur once, and reports a validation error otherwise.
Closes: gh-1304