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

fix: Return failing error code on invalid parameter #544

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

DaveTryon
Copy link
Contributor

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

@echo off
Microsoft.Sbom.DotNetTool.exe
echo %ERRORLEVEL%

Before the change, ERRORLEVEL is 0. After the change, ERRORLEVEL is 1

I also tested it with correct parameters and ensured that ERRORLEVEL was correctly set to 0

@DaveTryon DaveTryon requested a review from a team as a code owner April 9, 2024 23:43
@codecov-commenter
Copy link

codecov-commenter commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.66%. Comparing base (5424d2f) to head (8d6e97f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #544      +/-   ##
==========================================
- Coverage   59.70%   59.66%   -0.04%     
==========================================
  Files         248      248              
  Lines        7575     7575              
  Branches      901      901              
==========================================
- Hits         4523     4520       -3     
- Misses       2639     2642       +3     
  Partials      413      413              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@pownkel pownkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DaveTryon DaveTryon merged commit ca290a7 into microsoft:main Apr 10, 2024
6 checks passed
@DaveTryon DaveTryon deleted the fix-return-code-on-help branch April 10, 2024 17:02
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

Successfully merging this pull request may close these issues.

3 participants