better error handling for `infisical secret set`
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!
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.
I believe this issue is still present, I would propose to re-open it.