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]


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

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.


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.