Skip to content

Commit ced9572

Browse files
mergify[bot]facundomedicajulienrbrt
authored
feat(client/v2): improve error message on enums (backport #21936) (#21938)
Co-authored-by: Facundo Medica <[email protected]> Co-authored-by: Julien Robert <[email protected]>
1 parent 412f4e7 commit ced9572

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

client/v2/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
## [Unreleased]
3838

39+
### Improvements
40+
41+
* [#21936](https://github.com/cosmos/cosmos-sdk/pull/21936) Print possible enum values in error message after an invalid input was provided.
42+
3943
### Bug Fixes
4044

4145
* [#21809](https://github.com/cosmos/cosmos-sdk/pull/21809) Correctly handle enhanced sub commands.

client/v2/autocli/flag/enum.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ func (e enumValue) String() string {
5858
func (e *enumValue) Set(s string) error {
5959
valDesc, ok := e.valMap[s]
6060
if !ok {
61-
return fmt.Errorf("%s is not a valid value for enum %s", s, e.enum.FullName())
61+
var validValues []string
62+
for k := range e.valMap {
63+
validValues = append(validValues, k)
64+
}
65+
66+
return fmt.Errorf("%s is not a valid value for enum %s. Valid values are: %s", s, e.enum.FullName(), strings.Join(validValues, ", "))
6267
}
6368
e.value = valDesc.Number()
6469
return nil

0 commit comments

Comments
 (0)