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

This commit is contained in:
Facundo Medica 2024-09-26 20:03:48 +02:00 committed by GitHub
parent 2d8ca73afa
commit dc2cea5bcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -43,6 +43,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#18626](https://github.com/cosmos/cosmos-sdk/pull/18626) Support for off-chain signing and verification of a file.
* [#18461](https://github.com/cosmos/cosmos-sdk/pull/18461) Support governance proposals.
### Improvements
* [#21936](https://github.com/cosmos/cosmos-sdk/pull/21936) Print possible enum values in error message after an invalid input was provided.
### API Breaking Changes
* [#17709](https://github.com/cosmos/cosmos-sdk/pull/17709) Address codecs have been removed from `autocli.AppOptions` and `flag.Builder`. Instead client/v2 uses the address codecs present in the context (introduced in [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503)).

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