Display something more error-like when an AJAX block errors out

Bug #1605071 reported by Aaron Wells
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Medium
Aaron Wells
15.04
Won't Fix
Medium
Aaron Wells
15.10
Fix Released
Medium
Aaron Wells
16.04
Fix Released
Medium
Aaron Wells
16.10
Fix Released
Medium
Aaron Wells

Bug Description

Spinning this bug off from Bug 1544424 (Endless JS loop if there's an uncaught exception in an ajax block) since patch https://reviews.mahara.org/6055 has taken much longer than https://reviews.mahara.org/6054 to get merged.

We no longer get an endless loop when an Ajax block errors out, but it still looks pretty bad. See the attached screenshot. Because the file "blocktype.ajax.php" doesn't have the "JSON" header at its top, when it errors out, Mahara tries to print the full error page with the navigation headers and the message "Mahara: Site unavailable", and then ajaxblocks.js tries to display it in the little iframe reserved for that block.

This looks confusing to the user, and it can spill over out of that block's space and cover up adjacent blocks. It would be better if we printed something that more obviously indicates that just this one block is broken, and that doesn't break the display of other blocks.

Revision history for this message
Aaron Wells (u-aaronw) wrote :
Revision history for this message
Aaron Wells (u-aaronw) wrote :

Testing this requires causing an error or exception in one of the ajax block's render_instance methods. The easiest way to do this is to just add an exception into one of the core blocks:

1. Open up file htdocs/blocktype/newviews/lib.php
2. Locate the function "render_instance()" on line 32.
3. Inside that function, put an exception, like so:

    public static function render_instance(BlockInstance $instance, $editing=false) {
        global $USER;

        // here's an exception
        throw new Exception('die.');

        require_once('view.php');
        $configdata = $instance->get('configdata');
        $nviews = isset($configdata['limit']) ? intval($configdata['limit']) : 5;

4. Log in to Mahara and view your dashboard (which should contain a new views block as per the default)

Expected result: The new view block indicates that it has failed to load properly.

Actual result: The new view block displays an unreadable, compressed version of the Mahara page header. (See screenshot).

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Patch for master: https://reviews.mahara.org/#/c/6055/

This patch adds the "JSON" flag to blocktype.ajax.php, so that errors.php will print a JSON-encoded error response instead of trying to render the normal "Site unavailable" error page.

This isn't the cleanest option, but it's an improvement over the current state of affairs. It makes it clear to the user that something is wrong with that block, and it doesn't mess up the display of other blocks.

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/6055
Committed: https://git.mahara.org/mahara/mahara/commit/0e7c6ff5d291ea5f8427c4380b3646be4d1b49cc
Submitter: Son Nguyen (<email address hidden>)
Branch: master

commit 0e7c6ff5d291ea5f8427c4380b3646be4d1b49cc
Author: Aaron Wells <email address hidden>
Date: Thu Feb 11 18:34:17 2016 +1300

Bug 1605071: Display JSON-style errors for ajax blocks

If an Ajax block errors out, it will looks less broken
to display the JSON code there than to display error.tpl
(which tries to wedge a whole copy of the Mahara header and
footer and everything, into the space for a block.)

It would be even better to change block.js so that it actually
expects a JSON response.

behatnotneeded: Can't test error state via Behat

Change-Id: If5cc9ed2bbb3ce453a5cb413cbecdab0205fb3b5

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "16.04_STABLE" branch: https://reviews.mahara.org/6794

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "15.10_STABLE" branch: https://reviews.mahara.org/6795

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "15.04_STABLE" branch: https://reviews.mahara.org/6796

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/6795
Committed: https://git.mahara.org/mahara/mahara/commit/be39b7a42eedd7f6c7a48b370761e1d8617e2d83
Submitter: Robert Lyon (<email address hidden>)
Branch: 15.10_STABLE

commit be39b7a42eedd7f6c7a48b370761e1d8617e2d83
Author: Aaron Wells <email address hidden>
Date: Thu Feb 11 18:34:17 2016 +1300

Bug 1605071: Display JSON-style errors for ajax blocks

If an Ajax block errors out, it will looks less broken
to display the JSON code there than to display error.tpl
(which tries to wedge a whole copy of the Mahara header and
footer and everything, into the space for a block.)

It would be even better to change block.js so that it actually
expects a JSON response.

behatnotneeded: Can't test error state via Behat

Change-Id: If5cc9ed2bbb3ce453a5cb413cbecdab0205fb3b5
(cherry picked from commit 0e7c6ff5d291ea5f8427c4380b3646be4d1b49cc)

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/6794
Committed: https://git.mahara.org/mahara/mahara/commit/cc4e3cf5150747dd8e692a7db4d71215630a7955
Submitter: Robert Lyon (<email address hidden>)
Branch: 16.04_STABLE

commit cc4e3cf5150747dd8e692a7db4d71215630a7955
Author: Aaron Wells <email address hidden>
Date: Thu Feb 11 18:34:17 2016 +1300

Bug 1605071: Display JSON-style errors for ajax blocks

If an Ajax block errors out, it will looks less broken
to display the JSON code there than to display error.tpl
(which tries to wedge a whole copy of the Mahara header and
footer and everything, into the space for a block.)

It would be even better to change block.js so that it actually
expects a JSON response.

behatnotneeded: Can't test error state via Behat

Change-Id: If5cc9ed2bbb3ce453a5cb413cbecdab0205fb3b5
(cherry picked from commit 0e7c6ff5d291ea5f8427c4380b3646be4d1b49cc)

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Aborting the backport to 15.04_STABLE, because it caused a regression.

Robert Lyon (robertl-9)
Changed in mahara:
milestone: 16.10.0 → none
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.