SonarCloud Scan Suddenly Failing on Code Coverage Report

We suddenly experienced a weird behavior today in our SonarCloud scans in our Gitlab pipelines for Merge Requests. It suddenly reports:

Failed conditions
 25.0% Coverage on New Code (required ≥ 65%)

The codes that were modified were fully covered by tests.

Note that we did not perform any change in any of our Gitlab Pipelines nor did we change anything in our Sonar settings and configurations.

In the logs you can find entries:

22:36:11.409 INFO  Sensor JavaScript/TypeScript Coverage [javascript]
22:36:11.409 DEBUG Property sonar.javascript.lcov.reportPaths is used.
22:36:11.409 DEBUG Using 'coverage/lcov.info' to resolve LCOV files
22:36:11.410 INFO  Analysing [/builds/carboncure/orca/coverage/lcov.info]
22:36:11.565 WARN  Could not resolve 40 file paths in [/builds/carboncure/orca/coverage/lcov.info]
22:36:11.566 DEBUG Unresolved paths:
assetsTransformer.js
src/Common/Helpers/fakeDataHelpers.js
src/Echo/Data/EchoFakeDataHelpers.ts
....
..
... 42 files...

The file paths are existing in the project as have been verified from the paths defined.

The sonar cli image we are using is tagged with latest:

image:
    name: sonarsource/sonar-scanner-cli:latest

This is fully blocking our deployments as we need to ensure that all pipeline jobs are passing before we can merge changes.

This is the link to one of the failing MR in SonarCloud:

https://sonarcloud.io/dashboard?id=carboncure_orca&pullRequest=1331.

It’s really weird because in an MR pipeline run around April 3, 2025 at 11:25:10 AM MDT, the Sonar service was working fine and then a subsequent MR run with minimal file changes at around April 3, 2025 at 12:18:33 PM MDT resulted in the failed message.

Anyone has any insight on what could possibly caused this?

For additional context, I tested out with different scenarios:

Scenario 1: ReadMe.md Changes

  • Quality Gate succeeded (although presumably because there were no code file changes)
  • Still logged the error: Could not resolve 40 file paths in [/builds/<company>/<project>/coverage/lcov.info]

Scenario 2: Minimal Code Changes

  • Quality Gate Failed reporting a low code coverage
  • We inspected the coverage of the code files modified and can attest that the coverage is 100% (when you run the unit test on the file with --coverage parameter.

Note that Scenario 2 is happening on different MRs we have at the moment, with different branches being targeted.

Updates:
I have also tested by disabling sections of code from being scanned.

The code base has the following sonar-project.properties file with the entries:

sonar.issue.ignore.block=e1
sonar.issue.ignore.block.e1.beginBlockRegexp=@SONAR_STOP@
sonar.issue.ignore.block.e1.endBlockRegexp=@SONAR_START@

I added the tag @SONAR_STOP@ and @SONAR_START@ on sections of the code where I want to ignore for code coverage but the same are not being taken into consideration.

Hi,

This indicates that the paths in the coverage report don’t match the paths analysis is seeing. Let’s start with assetsTransformer.js. Where in the project is it located? And where is that, relative to where analysis kicks off?

This is an issues exclusion (hence the issue in the property name). So it’s not going to work at all for coverage.

 
Ann

I have been able to resolve the missing file paths in this instance. This was due to some exclusions made for files that we do not need for Sonar to scan.

This is an issues exclusion (hence the issue in the property name). So it’s not going to work at all for coverage.

Is there a mechanism to exclude portions of code from sonar cloud code coverage / quality scanning?

Hi,

You can exclude full files, but not parts of files.

 
HTH,
Ann