Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix: return non-0 exit code on pflag parse error
We are currently doing this pflag.Usage = func() { r.RunUsageExit() } That usage gets invoked if pflag fails to parse (e.g. due to an unknown flag), but then rather than letting pflag exit with a non-0 error code, the RunUsageExit() func exits with a 0 code, misleading callers into thinking we had a successful script invocation. That's a bug. We seem to be able to safely just remove the 'exit' part to fix it and still have everything else working properly. I took this opportunity to investigate the 'double unknown error' print issue a bit. It's a bug in the pflag lib, I'm not the only one to have found it: spf13/pflag#352 Unfortunately pflag is not maintained anymore (last release >5 years ago), so very small chance this is ever getting fixed. The only solution (bar forking pflag, but I don't think this is a legitimate reason to) is to switch to using our own flagset so that we can control the error handling to be ContinueOnError instead of ExitOnError. This way, we can then avoid the double print and handle the error ourselves. Anyway, that's a future ticket.
- Loading branch information