moodle exception thrown

moodle exception thrown

by Martin Meadows -
Number of replies: 9

In the last couple days, I've suddenly started having this problem when I try to enter the site administration menu. 

* line 101 of /lib/ajax/ajaxlib.php: coding_exception thrown
* line 54 of /lib/ajax/getsiteadminbranch.php: call to ajax_check_captured_output()

 

I started getting it with Moodle 2.6.1+ build 20140220 on two separate sites I maintain on two different servers. Both started "acting up" after I tried out the new PDF Annotation feature by creating an assignment, uploading some pdfs and then trying to grade them. On neither site could I save the results of grading. Then I got the above error message when I tried to access the site admin menu. 

Today I was able to upgrade both sites to the latest build 20140228. I can login on both sites as admin, but I can't access the site admin menu without the above error message appearing. I'm effectively locked out of making any changes in the site settings! 

Can anyone suggest some help? 

Thanks

 

Additional note: This is the full error message: if I could enter site admin, I could try turning off Ajax, but I'm locked out .... 

Coding error detected, it must be fixed by a programmer: Unexpected output whilst processing AJAX request. This could be caused by trailing whitespace. Output received: ' '
URL/
Debug info: Error code: codingerror
Stack trace:
* line 101 of /lib/ajax/ajaxlib.php: coding_exception thrown
* line 54 of /lib/ajax/getsiteadminbranch.php

 

 

Average of ratings: -
In reply to Martin Meadows

Re: moodle exception thrown

by Rodney Willott -

yoursite/moodle/admin/index.php should get you to the Site Administration menu to bypass this error.

Average of ratings: Useful (1)
In reply to Martin Meadows

Re: moodle exception thrown

by jasper boyd -

This is pretty shameful mistake for moodle, display the error message when there is output come on...

original code in lib/ajax/ajaxlib - line 71: 

================================

if (!empty($output)) {
        $message = 'Unexpected output whilst processing AJAX request. ' .
                'This could be caused by trailing whitespace. Output received: ' .
                var_export($output, true);
        if ($CFG->debugdeveloper && !empty($output)) {
            // Only throw an error if the site is in debugdeveloper.
            throw new coding_exception($message);
        }
        error_log('Potential coding error: ' . $message);
    }

===============================

This should clearly be:

===============================

if (empty($output))

============================

Average of ratings: Useful (1)
In reply to jasper boyd

Re: moodle exception thrown

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Jasper,

Thanks for jumping in, but I think you mis-understand the purpose of this section of code.

This section is in the ajax_check_captured_output() function, whose purpose is to check for any potential errors, or other unexpected output. It is always called after we have called ajax_capture_output() and we expect there to be no output at this stage.

Prior to the introduction of this code, any time that an AJAX query included a plugin file which has unexpected whitespace or content, this caused issues when the browser tried to decode what it expected to be a JSON request. If you take the example of a plugin which used echo to output a problem or debugging info, then this would be output before the expected JSON output, leading to output which may look like:

Couldn't find course 1{"id":"1","somecontent":["foo","bar","baz"]}

The browser is unable to correctly parse this and throws an error which is meaningless to the user and does not help to track the issue down at all. As a result, during AJAX scripts, we now look for and capture any unexpected output. The above block of code then decides what to do with that output. If the $output variable (where that unexpected output was captured to) is not empty (as in the if (!empty($output)) section you highlight in particular), then we log this to the web server's error log. If the site is additionally in the relevant debug mode, then we instead throw an exception which is caught by the JavaScript endpoint and displayed to the user.

Since we don't expect production sites to run with debugdeveloper, this should mean that production sites function as normal with the errors being logged to the web server log; whilst developer sites have information displayed to the user.

So, in summary, this is correct. There are a few changes I'd like to make (moving error_log to above the throw for example), but the code you highlight is spot-on.

Andrew

Average of ratings: Useful (1)
In reply to Martin Meadows

Re: moodle exception thrown

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Martin

Did you ever figure out your issue? I started experiencing the same issue on one of our sites with Moodle 2.7.10 today and was wondering if you might have figured out the solution.

Here is a screenshot of the dialogue box which appears when I click on the Site Administration link. Note that this only happens with debugging enabled. When it is disabled, everything works fine.

Attachment 2015-11-02-Site-Administration-Error.png
In reply to Michael Milette

Re: moodle exception thrown

by Susana L. -

Same problem with our moodle test site (2.7).

susana

In reply to Susana L.

Re: moodle exception thrown

by Dave Emsley -
In reply to Dave Emsley

Re: moodle exception thrown

by Henrik sune Pedersen -
Hi

We had the same problem in 2.9.4, and discovered that it was the vimeo filter that made the error.
if you have the filter installed, you can go into the filter folder and open the file filter.php.
At the bottom of the file remove the ?> and any empty lines.
Save the file
Clear cache
Reload.

Hope it works for you as well smile