Skip to content

Commit

Permalink
Print valid enum values when none match
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed May 15, 2024
1 parent 78da511 commit d195960
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/controller/direct/monitoring/maputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"
"time"

"google.golang.org/protobuf/reflect/protoreflect"
Expand Down Expand Up @@ -72,7 +73,13 @@ func Enum_ToProto[U ProtoEnum](ctx *MapContext, in *string) U {
}
}

ctx.Errorf("unknown enum value %q", in)
var validValues []string
for i := 0; i < n; i++ {
value := descriptor.Values().Get(i)
validValues = append(validValues, string(value.Name()))
}

ctx.Errorf("unknown enum value %q for %v (valid values are %v)", inValue, descriptor.FullName(), strings.Join(validValues, ", "))
return 0
}

Expand Down

0 comments on commit d195960

Please sign in to comment.