? ? Pending

User tests: Successful: Unsuccessful:

avatar mbabker
mbabker
7 Apr 2018

Summary of Changes

To do error handling correctly, you really need two levels of exception catching:

  • A global handler registered to PHP via set_exception_handler() that can function standalone (without application components in a usable state)
  • An application internal handler which can integrate with your application components

Right now we accomplish both with one method, and this can be problematic because it relies on the application framework being in a usable state, an exception caught and processed by the set_exception_handler() callback cannot make this guarantee.

So, this will change our application bootstrap and exception handling so that the set_exception_handler() callback is no longer our existing handler, but the one provided by Symfony's Debug component (as it is shipping in our package) and change CMSApplication::execute() so that it will catch exceptions and render the error page using our existing handler (which is now consistent with the new Console package application). By moving the catching logic into the application class itself, in the future we can make additional API improvements (because we can make arbitrary assumptions on the state of the application) such as being able to dispatch events for plugins to do custom error handling, and we can leave the global PHP handler as a minimalistic processor decoupled from the rest of the framework.

Testing Instructions

At a point in the application process after the error handler is registered and before the application's execute() method is called, throw an Exception; this should be caught by the Symfony handler and the error page their handler builds rendered. Throwing an exception anywhere after execute() is called should hit our handler and be rendered as has always been the case.

Potential Future Enhancements

  • Be able to toggle the $debug flag on Symfony's exception handler, which toggles whether a stack trace is displayed; because JConfig is loaded so late in the bootstrap process (which inherently means at the point we're registering the handler JDEBUG is not yet defined) we're unable to programmatically toggle this short of unregistering and reregistering the handler
  • Styling the rendered document in a Joomla theme versus the theme Symfony uses (see https://symfony.com/doc/3.4/controller/error_pages.html for an example)
avatar mbabker mbabker - open - 7 Apr 2018
avatar mbabker mbabker - change - 7 Apr 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Apr 2018
Category Installation Libraries
avatar mbabker mbabker - change - 7 Apr 2018
Labels Added: ?
avatar wilsonge
wilsonge - comment - 7 Apr 2018

I'm not against this approach at all - it seems to make lots of sense. But we need to figure out how https://github.com/joomla/joomla-cms/blob/4.0-dev/plugins/system/redirect/redirect.php#L58 works I guess - because doing this in a plugin is no longer going to work with this approach (and we know there are extensions also following the logic in the redirect plugin)

avatar mbabker
mbabker - comment - 7 Apr 2018

I didn't do a full implementation but the CMSApplication::execute() method would start to look a bit closer to the Console's Application::execute() which dispatches an event on error. So adding that event then updating the plugin to subscribe to it would take care of things.

avatar joomla-cms-bot joomla-cms-bot - change - 9 Apr 2018
Category Installation Libraries Installation Libraries Front End Plugins
avatar mbabker
mbabker - comment - 9 Apr 2018

OK, this is updated now to emit a new onError event with the thrown error, with the capability of altering it, and the redirect plugin updated for this pattern.

avatar joomla-cms-bot joomla-cms-bot - change - 15 May 2018
Category Installation Libraries Front End Plugins External Library Composer Change Installation Libraries Front End Plugins
avatar wilsonge wilsonge - change - 15 May 2018
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-05-15 16:48:07
Closed_By wilsonge
Labels Added: ?
avatar wilsonge wilsonge - close - 15 May 2018
avatar wilsonge wilsonge - merge - 15 May 2018

Add a Comment

Login with GitHub to post a comment