Parse error in sonar scanner for TSQL files

Hi,

I am using SonarQube version 6.5. I am getting an error while running the sonar-scanner on my tsql files on command line as " Unable to parse file : Parse error at line no column no:

I am getting this error for many files (all files are TSQL files) and I guess these files are skipped from the scanning process. When I checked few of the files I did not find any issue at the given line number.

Can anyone please help me understand the meaning of this error and how to avoid it or how to remove it?

Thanks.

Hi Swati,

The parse-error means that the TSQL code analyzer (built in SonarQube) was able to completely process the code file, potentially preventing accurate detection of issues.

It’s normal that you don’t necessarily see an issue in SonarQube at that line, that would depend on whether you do track parsing failures or not. For example: T-SQL static code analysis: Track parsing failures

A parse-error on valid code is an anomaly, and the SonarSource staff will be happy to improve the analyzer if you provide detailed steps to reproduce the parse-error. A good practice is to share a minimal source file that causes the same error when analyzer with SonarQube.

Last but not least: make sure to use the last version of the TSQL analyzer, https://docs.sonarqube.org/display/PLUG/SonarTSQL .

Hi Nicolas,

I am scanning TSQL files which have default encoding as “Western European (Windows) - Codepage 1252” and the encoding I am using in sonar-scanner.properties file is UTF-8. Could that be the reason for this error? If so, what encoding should I use here?

Also, what I understand from your reply is that these files which have a parse error will be scanned but static code issues will not be detected and pointed out correctly. Is that correct?

Hi Swati,

A parse error means the file was not successfully analyzed in its entirety, so yes it does mean that issue detection may not be exhaustive.

Good catch ! Yes using the wrong encoding can definitely cause problems. Check-out sonar.sourceEncoding analysis parameter , can definitely help out (windows-1252 might be worth trying).

Hi,

I was able to rule out the “Invalid character encountered in file at line no for encoding UTF-8” error by changing the encoding to “windows-1252”, but still getting same parse errors for the same files as I was getting when using UTF-8. I suppose the parse errors are not because of encoding and mean something else.

Below is the snapshot of the parse error. As seen, on command line the error is pointed out but in the code there is no invalid character. Any inputs would be really helpful. Thanks.

Image of the code:

image

Hi,

Before anything: are you using the latest version of TSQL analyzer ? (note: might have to upgrade SonarQube too as the 6.5 you mentioned is fairly old)

Hi,

Our TSQL parser does not support service broker statements like RECEIVE.
We will handle that: SONARTSQL-136

Thanks for the feedback.

1 Like

Hi Nicolas,
I faced with the same issue, I’m using Developer Edition Version 7.7 (build 23042) with built-in SonarTSQL plugin v1.4 (build 3334) is installed. And .sql scripts analyzing is very poor.
Could you please advise something?

Hi Maksim,

This thread is old and I don’t think that you’re facing “the same issue”.
I advise you to start a new thread and list the various errors you face (do they all appear in your screenshot?).
That would help us to help you.

Thanks.

A post was split to a new topic: Parse error scanning TSQL