Error parsing python coverage

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension): Community Build v25.2.0.102705

So I have a public repo: GitHub - baobabsoluciones/cornflow: An open source multi-solver optimization server with a REST API.

Where I have the following Github action: cornflow/.github/workflows/sonarqube.yml at develop · baobabsoluciones/cornflow · GitHub

This actions runs three different test suites and uploads their respective coverage reports as an artifact to be then downloaded and uploaded with the sonarqube scan action.

For that I have the following sonar-project.properties file:

# Project identification
sonar.projectKey=cornflow
sonar.projectVersion=1.0

# Source code location
sonar.sources=cornflow-dags,cornflow-server,libs
sonar.tests=cornflow-server/cornflow/tests,cornflow-dags/tests,libs/client/cornflow_client/tests

# Encoding of source files
sonar.sourceEncoding=UTF-8

# Coverage settings
sonar.python.coverage.reportPaths=coverage-server.xml,coverage-client.xml,coverage-dags.xml

# Python specific settings
sonar.python.version=3

# Exclusions
sonar.exclusions=**/__pycache__/**,**/*.pyc,**/venv/**,**/.env/**,docs/**,**/tests/**

When running the last job of the action I get the downloaded artifacts:

Found 3 artifact(s)
Filtering artifacts by pattern 'coverage-*.xml'
Preparing to download the following artifacts:
- coverage-client.xml (ID: 2905358904, Size: 5923, Expected Digest: sha256:113ae8d8f1e79e37bf3cc7fc3e419422883c6b9022038d7f12caf1f52c915c21)
- coverage-server.xml (ID: 2905312944, Size: 15019, Expected Digest: sha256:b3d67a6b482aa025741b4b446b46895adf69ddafc2e7c41526755292459f86b2)
- coverage-dags.xml (ID: 2905276006, Size: 19420, Expected Digest: sha256:00f9a57e44dddc590cc6a773ef5f095973d30d77bebde8148e4d1679b0037c33)
Redirecting to blob download url: https://productionresultssa13.blob.core.windows.net/actions-results/ba2047cc-f6c5-44ff-8b7b-e91555748a38/workflow-job-run-892519c9-2193-5677-6fbc-81aa76fa971a/artifacts/cca311c9bec5fc010c399b7408badcf85c3f218aff427b1c37af8d0b5d640195.zip
Starting download of artifact to: /home/runner/work/cornflow/cornflow/coverage-client.xml
Redirecting to blob download url: https://productionresultssa13.blob.core.windows.net/actions-results/0eb1a61b-60e9-4fae-a954-7401421df54e/workflow-job-run-8a0296dd-f818-5bdb-4cfb-a6b2ce09069b/artifacts/55b17eb6713003f3c7dd85e7d30a6f70ec6c365bcb0a450e12abbc3d8dd3a057.zip
Starting download of artifact to: /home/runner/work/cornflow/cornflow/coverage-server.xml
(node:1830) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Redirecting to blob download url: https://productionresultssa13.blob.core.windows.net/actions-results/0eb1a61b-60e9-4fae-a954-7401421df54e/workflow-job-run-ebc41999-9411-5e91-bb01-028bb8fcecc8/artifacts/9cdfefe77bba3ca16e4d1ad2030b7ac81fe9d894ed3094a25690555614882473.zip
Starting download of artifact to: /home/runner/work/cornflow/cornflow/coverage-dags.xml

And then I get the following warning on the sonarqube scan:

18:02:15.384 INFO  Python test coverage
18:02:15.385 INFO  Parsing report '/home/runner/work/cornflow/cornflow/coverage-server.xml'
18:02:15.395 WARN  Cannot read coverage report '/home/runner/work/cornflow/cornflow/coverage-server.xml', the following exception occurred: 'Error parsing the report '/home/runner/work/cornflow/cornflow/coverage-server.xml''
18:02:15.395 INFO  Parsing report '/home/runner/work/cornflow/cornflow/coverage-client.xml'
18:02:15.395 WARN  Cannot read coverage report '/home/runner/work/cornflow/cornflow/coverage-client.xml', the following exception occurred: 'Error parsing the report '/home/runner/work/cornflow/cornflow/coverage-client.xml''
18:02:15.395 INFO  Parsing report '/home/runner/work/cornflow/cornflow/coverage-dags.xml'
18:02:15.396 WARN  Cannot read coverage report '/home/runner/work/cornflow/cornflow/coverage-dags.xml', the following exception occurred: 'Error parsing the report '/home/runner/work/cornflow/cornflow/coverage-dags.xml''
18:02:15.396 INFO  Sensor Cobertura Sensor for Python coverage [python] (done) | time=64ms

I have attached one of the coverage reports so that it can be checked as well, but, why does the sonarqube scan action fail to parse the report? How can I get more informaton about the error?
coverage-client.xml.zip (5.8 KB)

EDIT: I have run the github action with loglevel DEBUG and verbose=true and the log does not contain more information about why the warning is getting raised and the coverage report can not be read.

Hi,

Welcome to the community!

To be clear, did you get DEBUG-level logging out of analysis itself? I’m trying to distinguish here between debug GHActions logging and debug analysis logging.

 
Thx,
Ann

I setted up these parameters on my sonar-project.properties file:

# Sonnar logging level
sonar.log.level=DEBUG

# Verbose logging
sonar.verbose=true
1 Like

Hi,

Thanks for confirming. Could you post the full, DEBUG analysis log (even tho there’s no extra data), redacted as necessary?

Since DEBUG was no help, I’m not sure where to go from here, so I’ve flagged this for the experts, and they’ll want to have it available.

 
Ann

1 Like

Sure thing, as the logs are too big I have attached them on a zip file.
logs_36984628980.zip (37.1 KB)

Please let me know if there is any extra information that I can provide that can be of help, the github action run is here: Corrected a bunch of more issues (#631) · baobabsoluciones/cornflow@0dd4d06 · GitHub

Hello @ggsdc and sorry for the late answer.

I must admit I am a bit puzzled by this issue. I have tested the coverage file you provided against our parser directly, as well as on a local instance of SonarQube, and the file got parsed without problem.

In order to troubleshoot this, could you try as well to import this report on a local instance of SonarQube and let me know if you still encounter the parse error? If you can’t reproduce the parse error locally, can you generate another file that does trigger this parse error? My assumption at this point would be that the file as it is imported is not the same as the one generated. Generally, what can happen in the context of GitHub Actions is that paths are inconsistent, but this wouldn’t lead to a parse error.

Cheers,
Guillaume

Hi, attached you can find the three separate coverage reports that fail on the Github Actions process.

coverage-dags.xml.zip (18.8 KB)
coverage-client.xml.zip (5.9 KB)
coverage-server.xml.zip (14.8 KB)

Again, here is the log for the action which should eb visible as it s a public repository:

Right now I can not test it out on a local instance of SonarQube.

Hello @ggsdc and sorry for coming back to this so late.

Since your project is public, I took the liberty to fork it and make a rough test on SonarQube Cloud, using the reports you provided.

As you can see here, the job ran as expected and coverage was imported properly. We can see that there are no failure in the logs, and the PR analysis shows coverage information.

One notable element is that, when I initially used the coverage reports from the “develop” branch in the “master” branch, I did get a parsing failure due to a mismatch between the lines of code in the source and the ones referenced in the coverage report (see here).

Consequently, I believe there might be a mismatch in how your coverage report is being generated, possibly targeting outdated sources. The problem does not seem to come from SonarQube itself or from the Python analyzer.

Hope that helps,
Guillaume

2 Likes

Hello Guillaume:

Sorry for the late response as I have been on leave for the past two months. If I understand this correctly, then the main issue is that there is a mitmatch between the coverage files and the actual source files?

Could this be because there is a lot of changes on source files between develop and master?

Would syncing these two branches help solve the issue?

Hello @ggsdc,

Yes, this is the issue. The coverage computed for one branch is probably being used when analyzed another branch, which leads to mismatches, and eventual failure of the import.

Whether you sync the branches or not is ultimately a decision that depends on what you want to do with the project: you don’t need to do it to fix this problem. The main fix for SonarQube is to generate the report on the same branch that you’re analyzing and trying to import coverage information.

Cheers,
Guillaume

But I do not understand that. Even if I point our SonarQube to the develop branch (again we are using SonarQube Community Edition, so we do not have PR analysis) I am not able to import the coverage run on the develop branch.

And the latest run:

and

And from the logs:

14:36:24.065 INFO  Python test coverage
14:36:24.067 INFO  Parsing report '/home/runner/work/cornflow/cornflow/coverage-server.xml'
14:36:24.075 WARN  Cannot read coverage report '/home/runner/work/cornflow/cornflow/coverage-server.xml', the following exception occurred: 'Error parsing the report '/home/runner/work/cornflow/cornflow/coverage-server.xml''
14:36:24.075 INFO  Parsing report '/home/runner/work/cornflow/cornflow/coverage-client.xml'
14:36:24.075 WARN  Cannot read coverage report '/home/runner/work/cornflow/cornflow/coverage-client.xml', the following exception occurred: 'Error parsing the report '/home/runner/work/cornflow/cornflow/coverage-client.xml''
14:36:24.075 INFO  Parsing report '/home/runner/work/cornflow/cornflow/coverage-dags.xml'
14:36:24.075 WARN  Cannot read coverage report '/home/runner/work/cornflow/cornflow/coverage-dags.xml', the following exception occurred: 'Error parsing the report '/home/runner/work/cornflow/cornflow/coverage-dags.xml''