fix: Return failing error code on invalid parameter #544
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.
As called out in #520, the sbom generation tool is a little inconsistent in how it handles return codes, returning a value of 0 if invalid parameters are passed in. This PR adds 2 lines to explicitly set the return values after displaying help or after successful completion. The successful completion is probably not necessary since we're setting to the default value, but being explicit here is low cost and makes the code (IMO) a little clearer. There was no obvious need to have a specific error code for invalid parameters, so we reuse
ExitCode.GeneralError
for this case. It's trivial to add a different error code if we later decide that we need to expose more information.Testing was simple--I ran the following script to launch the app and capture the return code. This needs to be a .bat file
Before the change,
ERRORLEVEL
is 0. After the change,ERRORLEVEL
is 1I also tested it with correct parameters and ensured that
ERRORLEVEL
was correctly set to 0