Instructing sonar-scanner to ignore errors?


(Adrian Blakey) #1

Is it possible to tell sonar-scanner to exclude files it cannot parse?

I have some bad code - specifically some XML files that can not be parsed, that are embedded among the code, I want to tell sonar-scanner not to stop if it encounters on of these files.

Right now the behavior is:

ERROR: Unable to analyse file some.xml
ERROR: Caused by: Unable to highlight file some.xml
ERROR: Caused by: 30 is not a valid line offset for pointer. File some.xml has 22 character(s) at line 4
Re-run SonarQube Scanner using the -X switch to enable full debug logging.

(vicky) #2

Hi @adrianblakey

Please refer this doc . Through sonar.exclusion in your, you can exclude required directory or files.
Easiest way is to go to the server URL after starting the server(localhost:8080) then login as admin,Go to Administration>General settings> Analysis scope > Source File Exclusions
here you can give the details to ignore the required directory or files.

I hope this helps!

(Adrian Blakey) #3

TY. Call me slow but - I only just realized that the scanner gets its configuration from the server. Good and bad - good: the admin gets to set global options; bad: because the client scanner knows much more about the specific tree it’s scanning and it might be able to selectively determine whether a specific file or directory should be scanned or not.

Ideally - I’d like some sort of api to allow the scanner to tell the server to exclude specific files/directories for a specific project. Also, it could be complemented by having a “rehearsal” mode to collect the names of files that can not be parsed, that could be sent to the server in the aforementioned api.

(Colin Mueller) #4

Setting exclusions in the project administration UI or in a file (or as analysis parameters, take your pic) will override defaults set at the global administration level :slight_smile: