Unable to parse file *.Scala file

Full Error

Unable to parse file: file:///D:/a/1/s/*.scala. Parse error at position 17:0
2019-09-12T07:45:07.0415130Z ##[error]

Description

Here, I am trying to scan notebooks which is created for Azure Data bricks and noticed that I have below code added for given line number for different notebooks.

  1. dbutils.widgets.text(“key”,“value”
  2. val variableName = “value”

Do we have support to run the SonarQube scan for Azure Databricks Runbook? If yes, please let me know to fix above issue.

SonarQube version?

SonarQube Scanner 3.2.0.1227

Hello @ghanchiasif, thanks for the feedback.

If I understand correctly, the two lines mentioned are automatically added to some of your Scala files, preventing them from being correctly analysed, is it correct?
To me, the error is correct, the first line is not valid Scala code and can not be correctly parsed, did I miss something?

In addition, the analysis fail due to this error?
If it is the case, this ticket seems to fix this issue, it will be available at the next release of SonarScala.

Best,
Quentin

Hi @Quentin,

We have scala notebooks created for Azure Databricks and they are valid syntax. Please refer below documents for both.

  1. https://docs.databricks.com/user-guide/notebooks/widgets.html
  2. https://docs.azuredatabricks.net/spark/latest/structured-streaming/examples.html

Please let me know if you need more information.

In order to help you, I need to know precisely the part of the code causing the failure, can you provide the failing file (here or privately) or, even better, a simple code snippet that you cannot analyse?

Hi @Quentin,

I uploaded 2 sample files with both examples and got below error with SonarQube scan.

##[error]ERROR: Unable to parse file: file:///D:/a/1/s/Notebooks/SonarQube/Sample_1.scala. Parse error at position 8:0
##[error]ERROR: Unable to parse file content.
##[error]ERROR: Unable to parse file: file:///D:/a/1/s/Notebooks/SonarQube/Sample_2.scala. Parse error at position 8:0
##[error]ERROR: Unable to parse file content.

(Note: Please remove .txt extension after downloading.)

I Sample_1.scala.txt (177 Bytes) Sample_2.scala.txt (213 Bytes)

Thanks for the two reproducers, the problem is clearer now.

The error comes from the fact that the file contains only Scala expressions that are not valid at the top-level for Scala programs. I created a ticket to improve the current situation, we will try to tackle it the next time we work on the plugin.

Finally, one of my concerns was that the analysis would fail due to this error, but it is not the case, so we are fine on this side.

Thank you for recognizing this situation and it seems this issue has been resolved. Does that mean the next release of sonarscanner will have this new feature?

The issue is addressed on SonarCloud and in SonarQube v8.5!

Sorry, I don’t understand. Isn’t that SonarQube relies on Sonarscanner to analyze code?

The scanner downloads analyzers from your SonarQube Server, makes sure the analysis happens (spitting out logs along the way), and then sends the analysis to the SonarQube server. Language analysis features ≠ the version of the scanner you’re using.

Thank you for explaining. But I just tried the v8.5 (Community Edition

  • Version 8.5.1 (build 38104)) and scala script files still return errors like below

Parse error at position 13:0
ERROR: Unable to parse file content.

below is the command I ran to analyze my project containing scala scripts:

sonar-scanner.bat -D"sonar.projectKey=intelligence" -D"sonar.sources=." -D"sonar.host.url=http://localhost:8000" -D"sonar.login=51f6a2609a5016259bc8186cc167b995af7a138c"

Whoops, :man_facepalming: I got my versions mixed up. The issue will be fixed in SonarQube v8.6, scheduled for the first few weeks of December.

That will be so great. Thank you for the help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.