feat(client/v2): improve error message on enums (backport #21936) (#21938)

Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
mergify[bot] 2024-09-26 19:28:07 +00:00 committed by GitHub
parent 412f4e719e
commit ced9572d86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
### Improvements
* [#21936](https://github.com/cosmos/cosmos-sdk/pull/21936) Print possible enum values in error message after an invalid input was provided.
### Bug Fixes
* [#21809](https://github.com/cosmos/cosmos-sdk/pull/21809) Correctly handle enhanced sub commands.

View File

@ -58,7 +58,12 @@ func (e enumValue) String() string {
func (e *enumValue) Set(s string) error {
valDesc, ok := e.valMap[s]
if !ok {
return fmt.Errorf("%s is not a valid value for enum %s", s, e.enum.FullName())
var validValues []string
for k := range e.valMap {
validValues = append(validValues, k)
}
return fmt.Errorf("%s is not a valid value for enum %s. Valid values are: %s", s, e.enum.FullName(), strings.Join(validValues, ", "))
}
e.value = valDesc.Number()
return nil