Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-58843

Exception handlers must not expect Exception instances only

XMLWordPrintable

      I have discovered this while debugging MDLSITE-5026. On moodle.net, we have error_log records like

      PHP Fatal error:  Uncaught TypeError: Argument 1 passed to webservice_xmlrpc_server::generate_error() must be an instance of Exception, instance of Error given, called in /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php on line 139 and defined in /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php:170
       
      Stack trace
      #0 /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php(139): webservice_xmlrpc_server->generate_error(Object(Error))
      #1 /var/www/vhosts/moodle.net/html/webservice/lib.php(1245): webservice_xmlrpc_server->send_error(Object(Error))
      #2 [internal function]: webservice_base_server->exception_handler(Object(Error))
      #3 {main}\n  thrown in /var/www/vhosts/moodle.net/html/webservice/xmlrpc/locallib.php on line 170
      

      As documented at http://php.net/manual/en/function.set-exception-handler.php, starting with PHP 7 the custom exception handlers are passed with Error instances beside the Exception instances (both of them implement Throwable).

      I suggest to do what PHPUnit did (https://github.com/sebastianbergmann/phpunit/commit/c3db067ba2f64843d6038c6dc9c51eca794f5e06) and get rid of the Exception type declaration in the handler signature.

            mudrd8mz David Mudrák (@mudrd8mz)
            mudrd8mz David Mudrák (@mudrd8mz)
            Ankit Agarwal Ankit Agarwal
            David Monllaó David Monllaó
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.