[SonarPython] Parse error generates ERROR level message output and returns an error code of 0

The SonarPython scanner detected a Parse error in one of the python files within my project, and reported it as such in the log messages:

INFO: Sensor Python Squid Sensor [python]
ERROR: Unable to parse file: C:/my_project/myfile.py
ERROR: Parse error at line 477 column 34:

  475: def do_some_things(self):
  476:     """Do some things"""
  -->      oid = self.my_id.next_val())
  478:     args = {
  479:     ...
WARN: No report was found for sonar.python.coverage.reportPath using pattern coverage.xml
INFO: Sensor Python Squid Sensor [python] (done) | time=1076ms

The sonar_scanner.bat file returned an error code of zero.

The analysis ultimately succeeded, and the quality gate passed. Navigating to the Code folder that the file resides in showed an empty value for lines of code (expected seeing as it could not be parsed)

image

When I navigate to the file that was unable to be parsed in the SonarQube UI, there is no markup indicating there was a problem.

I would expect that a non-zero error level was returned, and there is an error visible in SonarQube, as this is something I would like to be alerted to / enable me to fail my build.

SonarQube details are:

INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Windows 10 10.0 amd64
INFO: SonarQube server 7.2.1

You can activate the rule named “Python parser failure” so that an issue is raised for each parsing error.
Depending on your quality gate and on the severity you set for the rule in your quality profile, such issues may trigger a quality gate failure.

1 Like

Python parser failure is code smell , I’m trying to integrate this with GIT (CI/CD).
Can this be converted to bug type rule and be caught in pipeline?

Thanks
Sumeet