mibexsoftware / sonar-bitbucket-plugin

SonarQube plug-in to create pull request comments for found issues in Bitbucket Cloud
Other
123 stars 72 forks source link

Error during SonarQube Scanner execution ([sonar4bitbucket] Failed to parse diff: string matching regex `\z' expected but `F' found) #102

Open dnlowman opened 5 years ago

dnlowman commented 5 years ago

Expected Behavior

Scanner execution should behave as normal.

Actual Behavior

It's throwing the following exception: java.lang.RuntimeException: [sonar4bitbucket] Failed to parse diff: string matching regex\z' expected but F' found at ch.mibex.bitbucket.sonar.diff.IssuesOnChangedLinesFilter.parseOrFail(IssuesOnChangedLinesFilter.scala:54) at ch.mibex.bitbucket.sonar.diff.IssuesOnChangedLinesFilter.filter(IssuesOnChangedLinesFilter.scala:16) at ch.mibex.bitbucket.sonar.review.ReviewCommentsHandler.processIssues(ReviewCommentsHandler.scala:96) at ch.mibex.bitbucket.sonar.review.ReviewCommentsHandler.updateComments(ReviewCommentsHandler.scala:33) at ch.mibex.bitbucket.sonar.review.SonarReviewPostJob.ch$mibex$bitbucket$sonar$review$SonarReviewPostJob$$handlePullRequest(SonarReviewPostJob.scala:45) at ch.mibex.bitbucket.sonar.review.SonarReviewPostJob$$anonfun$execute$1.apply(SonarReviewPostJob.scala:29) at ch.mibex.bitbucket.sonar.review.SonarReviewPostJob$$anonfun$execute$1.apply(SonarReviewPostJob.scala:27) at scala.collection.immutable.List.foreach(List.scala:381) at ch.mibex.bitbucket.sonar.review.SonarReviewPostJob.execute(SonarReviewPostJob.scala:27) at org.sonar.scanner.postjob.PostJobWrapper.executeOn(PostJobWrapper.java:58) at org.sonar.scanner.phases.PostJobsExecutor.execute(PostJobsExecutor.java:66) at org.sonar.scanner.phases.PostJobsExecutor.execute(PostJobsExecutor.java:55) at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:94) at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:180) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121) at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:288) at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:283) at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:261) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121) at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48) at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121) at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121) at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116) at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71) at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) at com.sun.proxy.$Proxy0.execute(Unknown Source) at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171) at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128) at org.sonarsource.scanner.cli.Main.execute(Main.java:111) at org.sonarsource.scanner.cli.Main.execute(Main.java:75) at o

Plug-in version, SonarQube version, CI system, build type

We're using version v1.2.3 of the plugin, version 6.7.1 (build 35068) of SonarQube on Bitbucket Pipelines which is building a project with npm.

This issue is and could be related to this issue: #8 and I did try and follow some of steps which were identified there like ensuring line feeds are at the end of each file, I think the issue could lie with the value of the diff from the previous commit which is missing the LF at the end of the string.

vandammeb commented 5 years ago

Experiencing the same issue: Plugin version v1.2.3, SonarQube server 6.7.4 on Jenkins, building an npm project (Angular/Typescript)

Henridv commented 5 years ago

We're also experiencing this issue on v1.2.3 It looks like this happens with diffs containing a composer.lock.

failing.diff.txt

kaidjohnson commented 4 years ago

We were seeing the same issue, and I think I got to the bottom of it. The BB Excluded Files feature changes the diff of excluded files in their /diff/ api endpoint, such as:

diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml
index d1549e0..06b7b7d 100644
File excluded by pattern "pnpm-lock.yaml"

When I removed the Excluded Files configuration from our repo, the sonarqube plugin worked as expected.

I would be surprised if BB would accept this as a bug on their end, so I think the sonar-bitbucket-plugin needs to update its parsing handling for this scenario.

nfalco79 commented 4 years ago

we got the same issue

ERROR: Error during SonarQube Scanner execution ERROR: [sonar4bitbucket] Failed to parse diff: string matching regex \z' expected butB' found

but the "Exclude files from pull request diffs" is empty in repository settings. So the issue seems to be caused from different reason

Maybe our case is:

diff --git a/solutions/_templates/hybrid-solution/mvn/login/assets/logo.png b/solutions/_templates/hybrid/mvn/login/assets/logo.png
similarity index 100%
rename from solutions/_templates/hybrid-solution/mvn/login/assets/logo.png
rename to solutions/_templates/hybrid/mvn/login/assets/logo.png
Binary files a/solutions/_templates/hybrid-solution/mvn/login/assets/logo.png and b/solutions/_templates/hybrid/mvn/login/assets/logo.png differ
nfalco79 commented 4 years ago

@mrueegg any chance to get these fixed?

LauraCameran commented 4 years ago

@kaidjohnson I think I found a solution for your problem, check pull request #118 . I hope it also solves your problem @dnlowman

swaroop1012 commented 3 years ago

@nfalco79 Were you able to find the solution to your issue? I'm facing a similar issue because of which my sonar analysis is failing. Is there a way I can skip diff --git on all .png files?

diff --git a/test/security/images/security_vault.png b/test/security/images/security_vault.png
new file mode 100644
index 0000000..c73bf4c
Binary files /dev/null and b/test/security/images/security_vault.png differ
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project demo-service: [sonar4bitbucket] Failed to parse diff: string matching regex `\z' expected but `B' found -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project demo-service: [sonar4bitbucket] Failed to parse diff: string matching regex `\z' expected but `B' found
nfalco79 commented 3 years ago

built using the #118

swaroop1012 commented 3 years ago

@nfalco79 Thanks Nikolas!

kaidjohnson commented 3 years ago

118 looks like it addresses known comments in BB diffs. Might not cover all use-cases, but seems to fix the Excluded Files and Binary file diff outputs. Thank you!