SonarQube PHP
  1. SonarQube PHP
  2. SONARPHP-183

Improve error reporting when executing external tools

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.4
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Currently, when debug output is not enabled, we only get the return code of php executable when something goes wrong. For example:

      [INFO]  Executing PHPCodeSniffer with command 'phpcs --report-file=/home/s27697/.hudson/jobs/GEC_TestPHP/workspace/target/logs/codesniffer.xml --report=checkstyle --standard=/home/s27697/.hudson/jobs/GEC_TestPHP/workspace/target/logs/ruleset3563104260756670494.xml --extensions=php,php3,php4,php5,phtml,inc /home/s27697/.hudson/jobs/GEC_TestPHP/workspace/src/main/php'
      [INFO]  PHPCodeSniffer ended with returned code '255'.
      

      Also the process is not stopped when the return code is bad, but will likely fail later and that make understanding of the error difficult.
      When enabling debug output (-X with Maven) we can see the real error cause but this is very verbose. For example:

      [INFO]  Executing PHPCodeSniffer with command 'phpcs --report-file=/home/s27697/.hudson/jobs/GEC_TestPHP/workspace/target/logs/codesniffer.xml --report=checkstyle --standard=/home/s27697/.hudson/jobs/GEC_TestPHP/workspace/target/logs/ruleset6901610168221238437.xml --extensions=php,php3,php4,php5,phtml,inc /home/s27697/.hudson/jobs/GEC_TestPHP/workspace/src/main/php'
      [DEBUG]  
      [DEBUG]  Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 72 bytes) in /usr/share/php/PHP/CodeSniffer.php on line 1392
      [DEBUG]  
      [DEBUG]  Call Stack:
      [DEBUG]      0.0003     120472   1. {main}() /usr/bin/phpcs:0
      [DEBUG]      0.0338    2036448   2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38
      [DEBUG]      0.0344    2051520   3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:542
      [DEBUG]      1.3095   10218648   4. PHP_CodeSniffer->processFile() /usr/share/php/PHP/CodeSniffer.php:484
      [DEBUG]      1.3096   10218648   5. PHP_CodeSniffer->_processFile() /usr/share/php/PHP/CodeSniffer.php:1132
      [DEBUG]      1.3097   10219184   6. PHP_CodeSniffer_File->start() /usr/share/php/PHP/CodeSniffer.php:1252
      [DEBUG]      1.3097   10219184   7. PHP_CodeSniffer_File->_parse() /usr/share/php/PHP/CodeSniffer/File.php:383
      [DEBUG]      1.3099   10290528   8. PHP_CodeSniffer_File::tokenizeString() /usr/share/php/PHP/CodeSniffer/File.php:587
      [DEBUG]      1.3099   10290528   9. PHP_CodeSniffer_Tokenizers_PHP->tokenizeString() /usr/share/php/PHP/CodeSniffer/File.php:951
      [DEBUG]      1.5315   33547320  10. PHP_CodeSniffer::standardiseToken() /usr/share/php/PHP/CodeSniffer/Tokenizers/PHP.php:384
      [DEBUG]  
      [INFO]  PHPCodeSniffer ended with returned code '255'.
      

      What I am expecting is the following log when debug mode is not enabled:

      [INFO]  Executing PHPCodeSniffer with command 'phpcs --report-file=/home/s27697/.hudson/jobs/GEC_TestPHP/workspace/target/logs/codesniffer.xml --report=checkstyle --standard=/home/s27697/.hudson/jobs/GEC_TestPHP/workspace/target/logs/ruleset3563104260756670494.xml --extensions=php,php3,php4,php5,phtml,inc /home/s27697/.hudson/jobs/GEC_TestPHP/workspace/src/main/php'
      [ERROR]  Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 72 bytes) in /usr/share/php/PHP/CodeSniffer.php on line 1392
      [ERROR]  PHPCodeSniffer ended with returned code '255'.
      

      Then build fail at this point.

      I don't know if it could be implemented by a generic way or if a parsing of the output of each tool is required.

        Issue Links

          Activity

          Hide
          Gennadiy Litvinyuk added a comment -

          This is actually output of PHP... including call stack

          Show
          Gennadiy Litvinyuk added a comment - This is actually output of PHP... including call stack
          Hide
          Fabrice Bellingard added a comment -

          I think that using the latest version of the CommandExecutor class of the Sonar API should help with that. The following ticket should help even more: SONAR-2969.

          Show
          Fabrice Bellingard added a comment - I think that using the latest version of the CommandExecutor class of the Sonar API should help with that. The following ticket should help even more: SONAR-2969 .
          Hide
          Fabrice Bellingard added a comment -

          Implemented in r4904:

          • Replaced the current implementation by the Sonar CommandExecutor component, which automatically displays the process output in the log
          • Added a timeout parameter for each tool (default value: 30 minutes)
          • Added a verification of the exit codes of the PHP tool to make the Sonar analysis fail when it must fail

          I haven't tried to filter the output of external processes (as you suggested Julien) as the CommandExecutor class from Sonar does not allow to do so yet. So from now on, everything is printed out in the log (which is better than printing nothing actually).

          Show
          Fabrice Bellingard added a comment - Implemented in r4904: Replaced the current implementation by the Sonar CommandExecutor component, which automatically displays the process output in the log Added a timeout parameter for each tool (default value: 30 minutes) Added a verification of the exit codes of the PHP tool to make the Sonar analysis fail when it must fail I haven't tried to filter the output of external processes (as you suggested Julien) as the CommandExecutor class from Sonar does not allow to do so yet. So from now on, everything is printed out in the log (which is better than printing nothing actually).

            People

            • Assignee:
              Fabrice Bellingard
              Reporter:
              Julien HENRY
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: