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

better error handling for infisical secret set #1839

Open
harveysanders opened this issue May 16, 2024 · 1 comment
Open

better error handling for infisical secret set #1839

harveysanders opened this issue May 16, 2024 · 1 comment
Assignees

Comments

@harveysanders
Copy link

If you omit the = sign from secrets set command, the CLI panics:

infisical secrets set LABEL value
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/Infisical/infisical-merge/packages/cmd.init.func20(0x9231ba0, {0xc00024fd20, 0x2, 0x8bf1f75?})
	github.com/Infisical/infisical-merge/packages/cmd/secrets.go:230 +0x245c
github.com/spf13/cobra.(*Command).execute(0x9231ba0, {0xc00024fce0, 0x2, 0x2})
	github.com/spf13/[email protected]/command.go:920 +0x867
github.com/spf13/cobra.(*Command).ExecuteC(0x92301c0)
	github.com/spf13/[email protected]/command.go:1044 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:968
github.com/Infisical/infisical-merge/packages/cmd.Execute()
	github.com/Infisical/infisical-merge/packages/cmd/root.go:32 +0x1a
main.main()
	github.com/Infisical/infisical-merge/main.go:16 +0x13e

The panic is caused by the following code:
https://github.com/Infisical/infisical/blob/main/cli/packages/cmd/secrets.go#L229-L232

This could be better handled by the CLI. For example, if we check the bound of the splitKeyValueFromArg slice, we can provide a more user-friendly error message:

splitKeyValueFromArg := strings.SplitN(arg, "=", 2)
	if len(splitKeyValueFromArg) != 2 ||
		(splitKeyValueFromArg[0] == "" || splitKeyValueFromArg[1] == "") {

		util.PrintErrorMessageAndExit("ensure that each secret has a none empty key and value. Modify the input and try again")
	}

I'm happy to put in a PR if you all are interested in this change.

Thanks for building this tool!

@gzuidhof
Copy link
Contributor

I also ran into this immediately, perhaps it's possible to lean on Cobra instead of having your own splitting logic. You can use strings.Cut to split exactly once, see https://pkg.go.dev/strings#Cut.

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

3 participants