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

Exceptions are not handled in ajax requests

    XMLWordPrintable

Details

    • MOODLE_29_STABLE, MOODLE_30_STABLE, MOODLE_31_STABLE, MOODLE_32_STABLE
    • MOODLE_32_STABLE, MOODLE_33_STABLE
    • MDL-57103-master
    • Hide
      1. Generate a fake error:

        diff --git a/lib/ajax/service.php b/lib/ajax/service.php
        index 3298c0e7a7..044903137e 100644
        --- a/lib/ajax/service.php
        +++ b/lib/ajax/service.php
        @@ -41,6 +40,7 @@ if ($requests === null) {
             $lasterror = json_last_error_msg();
             throw new coding_exception('Invalid json in request: ' . $lasterror);
         }
        +throw new coding_exception('oh no!');
         $responses = array();
         
         // Defines the external settings required for Ajax processing.
        

      2. Load the messaging interface
      3. Make sure a modal pops up with information about the error
      4. Go to /lib/ajax/service.php?sesskey=blah
      5. You should see JSON not html
      6. Go to Site administrations > User policies
      7. Turn auto log in as guest on
      8. Open site administration in a new 'incognito' or 'private' tab to trigger an exception.
      9. Make sure the error displays on a static page, with full moodle headers and footers etc
      10. Throw an error in a cli script (use the test.php attached below)
      11. Make sure the error is displayed in plain text surrounded by !!! exclamation marks !!!
      Show
      Generate a fake error: diff --git a/lib/ajax/service.php b/lib/ajax/service.php index 3298c0e7a7..044903137e 100644 --- a/lib/ajax/service.php +++ b/lib/ajax/service.php @@ -41,6 +40,7 @@ if ($requests === null) { $lasterror = json_last_error_msg(); throw new coding_exception('Invalid json in request: ' . $lasterror); } +throw new coding_exception('oh no!'); $responses = array(); // Defines the external settings required for Ajax processing. Load the messaging interface Make sure a modal pops up with information about the error Go to /lib/ajax/service.php?sesskey=blah You should see JSON not html Go to Site administrations > User policies Turn auto log in as guest on Open site administration in a new 'incognito' or 'private' tab to trigger an exception. Make sure the error displays on a static page, with full moodle headers and footers etc Throw an error in a cli script (use the test.php attached below) Make sure the error is displayed in plain text surrounded by !!! exclamation marks !!!
    • 3.4 Sprint 1

    Description

      Since the change in MDL-56958 exceptions are not handled in ajax requests

      lib/ajax/service.php returns html and the ajax handlers never detect the error.

      Steps to reproduce:

      1. Generate a fake error:

      diff --git a/lib/ajax/service.php b/lib/ajax/service.php
      index 3298c0e7a7..044903137e 100644
      --- a/lib/ajax/service.php
      +++ b/lib/ajax/service.php
      @@ -41,6 +40,7 @@ if ($requests === null) {
           $lasterror = json_last_error_msg();
           throw new coding_exception('Invalid json in request: ' . $lasterror);
       }
      +throw new coding_exception('oh no!');
       $responses = array();
       
       // Defines the external settings required for Ajax processing.
      

      2. Load the messaging interface

      Expected result:

      • The error is reported

      Actual result:
      * The error is silently ignored

      Attachments

        Issue Links

          Activity

            People

              johno John Okely
              poltawski Dan Poltawski
              Damyon Wiese Damyon Wiese
              Jake Dallimore Jake Dallimore
              David Monllaó David Monllaó
              David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              4 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                10/Jul/17