sonar-scanner-msbuild icon indicating copy to clipboard operation
sonar-scanner-msbuild copied to clipboard

Refactor ArgumentProcessor to remove generic error message

Open sebastien-marichal opened this issue 1 year ago • 0 comments

Today, if ArgumentProcessor.TryProcessArgs returns null, it will always produce the following message:

Expecting at least the following command line argument:
- SonarQube/SonarCloud project key
The full path to a settings file can also be supplied. If it is not supplied, the exe will attempt to locate a default settings file in the same directory as the SonarQube Scanner for MSBuild.
Use '/?' or '/h' to see the help message.

For instance, it will return null if the user provides an invalid project key (containing invalid characters), and will produce two error messages:

  • One for the invalid project key
  • The generic one, even though the project key has been provided

ArgumentProcessor needs to be refactored to handle all argument-related errors (missing mandatory arguments and invalid arguments) to display specific/explicit error messages for each case.

This refactor should include the URI format check added in #1556, moving it to ArgumentProcessor.

Steps to reproduce

SonarScanner.MSBuild.exe begin /k:#test

Output

15:45:54.7  15:45:54.7  Invalid project key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.
15:45:54.7  Expecting at least the following command line argument:
- SonarQube/SonarCloud project key
The full path to a settings file can also be supplied. If it is not supplied, the exe will attempt to locate a default settings file in the same directory as the SonarQube Scanner for MSBuild.
Use '/?' or '/h' to see the help message.
15:45:54.701  Pre-processing failed. Exit code: 1

sebastien-marichal avatar Apr 03 '23 13:04 sebastien-marichal