Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Error Message When Parsing INT Enum Values #415

Open
isoldmysoull opened this issue Feb 25, 2024 · 0 comments
Open

Incorrect Error Message When Parsing INT Enum Values #415

isoldmysoull opened this issue Feb 25, 2024 · 0 comments

Comments

@isoldmysoull
Copy link

The following code:

package main

import (
	"fmt"
	"github.com/alecthomas/kong"
	kongyaml "github.com/alecthomas/kong-yaml"
	"os"
	"strings"
)

type CLI struct {
	UserEnumType int `required:"" enum:"1,2,3,4,5"`
}

func main() {
	data := `user-enum-type: 44423`
	resolver, err := kongyaml.Loader(strings.NewReader(data))
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		os.Exit(1)
	}
	var cli CLI
	parser, err := kong.New(&cli, kong.Resolvers(resolver))
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		os.Exit(1)
	}
	_, err = parser.Parse(nil)
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("UserEnumType: %d\n", cli.UserEnumType)
}

returns an weird error like this:

Err: --user-enum-type must be one of "1","2","3","4","5" but got ''

it should be but got '44423'.
this only happens to INT. strings works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant