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

panic occurs when defining a flag without default #232

Open
plastikfan opened this issue Dec 6, 2023 · 0 comments
Open

panic occurs when defining a flag without default #232

plastikfan opened this issue Dec 6, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@plastikfan
Copy link
Contributor

plastikfan commented Dec 6, 2023

eg:

• [PANICKED] [0.013 seconds]
SamplerRunner sampler [It] 🧪 ===> given: 'profile without no-files in args', should: 'sample(first) with glob filter, using no-files from config'
/Users/plastikfan/dev/github/snivilised/pixa/src/app/proxy/sampler-runner_test.go:157

  [PANICKED] Test Panicked
  In [It] at: /usr/local/Cellar/go/1.21.3/libexec/src/runtime/iface.go:263 @ 12/06/23 14:12:48.45

  interface conversion: interface {} is nil, not uint

  Full Stack Trace
    github.com/snivilised/cobrass/src/assistant.(*ParamSet[...]).BindUint(0x2586f88, 0x22005b8?, 0x50?)
    	/Users/plastikfan/go/pkg/mod/github.com/snivilised/cobrass@v0.3.6/src/assistant/param-set-auto.go:725 +0xee
    github.com/snivilised/cobrass/src/assistant.(*ParamSet[...]).BindValidatedUintWithin(0x196db80, 0xc0000aee10, 0xc0003c0b18, 0x1, 0x80)
    	/Users/plastikfan/go/pkg/mod/github.com/snivilised/cobrass@v0.3.6/src/assistant/param-set-binder-helpers-auto.go:2720 +0x4b
    github.com/snivilised/pixa/src/app/command.(*Bootstrap).buildRootCommand(0x1821aa0?, 0xc0000c7548)
    	/Users/plastikfan/dev/github/snivilised/pixa/src/app/command/root-cmd.go:75 +0x425
    github.com/snivilised/pixa/src/app/command.(*Bootstrap).Root(0xc0003642d0, {0xc000107740, 0x1, 0x0?})
    	/Users/plastikfan/dev/github/snivilised/pixa/src/app/command/bootstrap.go:146 +0x57f
    github.com/snivilised/pixa/src/app/proxy_test.glob..func3.3(0xc0001c4620)
    	/Users/plastikfan/dev/github/snivilised/pixa/src/app/proxy/sampler-runner_test.go:103 +0x1f9
    reflect.Value.call({0x1714640?, 0xc0000c68d0?, 0x13?}, {0x1821bc0, 0x4}, {0xc0000c7128, 0x1, 0x1?})
    	/usr/local/Cellar/go/1.21.3/libexec/src/reflect/value.go:596 +0xce7
    reflect.Value.Call({0x1714640?, 0xc0000c68d0?, 0x1964008?}, {0xc0000c7128?, 0x1011545?, 0x50?})
    	/usr/local/Cellar/go/1.21.3/libexec/src/reflect/value.go:380 +0xb9
------------------------------

caused in pixa from the following definition:

	// --no-files (pending: sampling-family)
	//
	paramSet.BindValidatedUintWithin(
		&assistant.FlagInfo{
			Name: "no-files",
			Usage: i18n.LeadsWith(
				"no-files",
				xi18n.Text(i18n.RootCmdNoFilesUsageTemplData{}),
			),
			// Default:            defFSItems,
			AlternativeFlagSet: rootCommand.PersistentFlags(),
		},
		&paramSet.Native.NoFiles,
		minFSItems,
		maxFSItems,
	)

Should be handled more gracefully.

could be caused by this code:

// BindUint binds uint slice flag with a shorthand if
// 'info.Short' has been set otherwise binds without a short name.
func (params *ParamSet[N]) BindUint(info *FlagInfo, to *uint) *ParamSet[N] {
	flagSet := params.ResolveFlagSet(info)
	if info.Short == "" {
		flagSet.UintVar(to, info.FlagName(), info.Default.(uint), info.Usage)
	} else {
		flagSet.UintVarP(to, info.FlagName(), info.Short, info.Default.(uint), info.Usage)
	}

	return params
}

ie, Default is being used without being checked.

@plastikfan plastikfan self-assigned this Dec 6, 2023
@plastikfan plastikfan added the bug Something isn't working label Dec 6, 2023
@plastikfan plastikfan changed the title panic occurs with defining a flag without default panic occurs when defining a flag without default Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant