Properly error out when input file doesn't exist #1640
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the change
This fixes a bug in the
kubeseal
CLI where it silently and errorneously does nothing and returns a 0 (eg: success) exit code when a specified--secret-file
does not exist (or is unreadable).It looks like there was a simple oversight in #1030, and as noted in that PR:
I just tweaked the exit logic to output an error message and exit with nonzero status, which I think is much more reasonable behavior as it is both less surprising and also follows what other POSIX-y CLIs do when they are pointed to files that don't exist.
Benefits
Instead of silently doing nothing and erroneously returning a success status/exit code, this will now clearly indicate that the problem occurred and programmatically indicate a non-successful result. I'm not super happy with the error message (I think it could be written better), but this is my first PR for a Go project, so I'm not sure what the culture of error messages is in the Go community (constructive guidance will be welcome and appreciated!).
Possible drawbacks
Anybody who has been relying on the previous -- non-standard -- behavior will be impacted by this change. But, also as noted in #1030:
Applicable issues
Additional information
This is my first ever foray into Golang, so I might need more hand-holding than your average contributor, especially around how to test this. TIA. 😄
Edit: Added example.