User tests: Successful: Unsuccessful:
To do error handling correctly, you really need two levels of exception catching:
set_exception_handler()
that can function standalone (without application components in a usable state)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.
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.
$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 handlerStatus | New | ⇒ | Pending |
Category | ⇒ | Installation Libraries |
Labels |
Added:
?
|
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.
Category | Installation Libraries | ⇒ | Installation Libraries Front End Plugins |
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.
Category | Installation Libraries Front End Plugins | ⇒ | External Library Composer Change Installation Libraries Front End Plugins |
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:
?
|
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)