Code Coverage line number error

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
    GitHub
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
    TeamCity
  • Scanner command used when applicable (private details masked)
    n/a
  • Languages of the repository
    C#, Typescript, TSQL
  • Only if the SonarCloud project is public, the URL
    n/a
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
    I’m trying to import Code Coverage data & I’m getting an error that the line numbers don’t match the files.
    We use NCrunch to run the unit tests & it outputs a OpenCover xml file. The NCrunch team have confirmed the OpenCover file looks right (OpenCover report - Daily Usage Issues - NCrunch Forum), yet Sonar throws an error. The error isn’t limited to just this file, it can be whatever file Sonar decides to start with.

It feels like an off-by-one error.

INFO: Sensor C# Tests Coverage Report Import [csharp]
19:08:08   INFO: Parsing the OpenCover report E:\BuildAgent\work\727bac85dde6f437\NCrunchResults\OpenCover.xml
19:08:09   INFO: Adding this code coverage report to the cache for later reuse: E:\BuildAgent\work\727bac85dde6f437\NCrunchResults\OpenCover.xml
19:08:20   INFO: Time spent writing ucfgs 16349ms
19:08:25   INFO: ------------------------------------------------------------------------
19:08:25   INFO: EXECUTION FAILURE
19:08:25   INFO: ------------------------------------------------------------------------
19:08:25   INFO: Total time: 4:33.904s
19:08:25   INFO: Final Memory: 76M/296M
19:08:25   ERROR: Error during SonarScanner execution
19:08:25   INFO: ------------------------------------------------------------------------
19:08:25   java.lang.IllegalStateException: Line 23 is out of range in the file project/Validators/EmailTemplateModelValidator.cs (lines: 22)
19:08:25     at org.sonar.api.utils.Preconditions.checkState(Preconditions.java:61)
19:08:25     at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(DefaultCoverage.java:67)
19:08:25     at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.lineHits(DefaultCoverage.java:55)
19:08:25     at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.analyzeCoverage(CoverageReportImportSensor.java:139)
19:08:25     at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.analyze(CoverageReportImportSensor.java:116)
19:08:25     at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.execute(CoverageReportImportSensor.java:84)
19:08:25     at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:62)
19:08:25     at org.sonar.scanner.sensor.ProjectSensorsExecutor.execute(ProjectSensorsExecutor.java:38)
19:08:25     at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:423)
19:08:25     at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
19:08:25     at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
19:08:25     at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:130)
19:08:25     at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
19:08:25     at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
19:08:25     at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
19:08:25     at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
19:08:25     at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
19:08:25     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:08:25     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
19:08:25     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
19:08:25     at java.base/java.lang.reflect.Method.invoke(Method.java:567)
19:08:25     at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
19:08:25     at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
19:08:25     at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
19:08:25     at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
19:08:25     at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
19:08:25     at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
19:08:25     at org.sonarsource.scanner.cli.Main.main(Main.java:61)
19:08:25   ERROR:
19:08:25   The SonarScanner did not complete successfully
19:08:25   19:08:25.775  Post-processing failed. Exit code: 1
19:08:25   Process exited with code 0

  • Steps to reproduce
  • Potential workaround

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi @simongh,

Thanks a lot for your feedback. Would it be possible to create a reproducer for us? If not, would it be possible to share the code file and the generated coverage?

Thanks,
Costin

let me see what I can do. I’m sure I can find a file without anything we can’t share in it

Hello @simongh

In addition, could you please share the debug logs with us?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)