Early error content - error pages when Moodle is broken

Early error content - error pages when Moodle is broken

by Joost Elshoff -
Number of replies: 2
Picture of Particularly helpful Moodlers Picture of Testers

Hi community,

I've worked with many instances of Moodle over the years and the software has improved a lot, except for this one bit that still looks like it has been created a long time ago:

The error pages Moodle generates when something prevents Moodle from properly loading., You know..., the white page with a yellow block and red text in the middle stating the error encountered when trying to load the site. Like the one below:

Voor veiligheidsredenen zijn enkel https-connecties toegelaten.

Is there any way these error pages can be made to look more up to date, without having to hack core code?

Average of ratings: -
In reply to Joost Elshoff

Re: Early error content - error pages when Moodle is broken

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You have to hack core code for this.

The thing about this page is: if this page is being shown, then almost anything could be broken. E.g. no database (so mostly no $CFG), no moodledata, no caches. So, it has to be implemented with the simples possible code, and be completely self-contained.

The way to customise this with minimal code code changes is:

  • Make a function that renders your own error page. A place like local/customerrors/lib.php might be a neat place to put that.
  • Find the place in  where Moodle renders its version of the page (the early_error_content static method in boostrap_renderer in setup.lib.php). Change that function to call your function instead. That is, right at the start add:
// Customisation of core code starts.
require_once($CFG->dirroot . '/local/customerrors/lib.php');
return my_early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo);
// Customisation of core code end.

Now I think about this, we could have an option, set in config.php, like $CFG->custom_early_error_page, to avoid the need for core code changes.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Early error content - error pages when Moodle is broken

by Joost Elshoff -
Picture of Particularly helpful Moodlers Picture of Testers

Hi Tim,

Thanks for your answer. It's our company's policy to stay away from hacking core code, as this makes updates and upgrades a lot harder to manage. I would be interested to see if the core developers can come up with a more up to date way to display these error pages or, as you suggested, a way to configure custom error pages.