Lack of interest XF\Error should be extendable

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

DragonByte Tech

Well-known member
Function calls like $exceptionMessage = $this->adjustExceptionMessage($e->getMessage(), $e); with the code
PHP:
    protected function adjustExceptionMessage($message, $e)
    {
        return $message;
    }

Implies that XF\Error should be extendable, but it isn't:
PHP:
        $container['error'] = function ()
        {
            return new Error($this);
        };
 
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
The adjustExceptionMessage method was added amongst a commit for something else in 2019 and it's not entirely clear what its intention was. It is very likely to be intentional that it isn't extendable as-is fairly common for these very low level classes.

I'll leave it open as we can consider it but for now one reliable way to extend it is through src/config.php where you can use something like:

PHP:
$c->extend('error', function (\XF\Error $error)
{
    return new \Your\Custom\Error\Class(\XF::app());
});

It may be possible to do in a similar way through an app_setup listener in your add-on. I'd be more cautious with this though as it isn't clear to me what would happen if the error container is touched (and therefore cached) before your code executes. This may result in your extended Error object not actually being available. This may be why it's not extendable in the first place. Worth testing, but certainly the src/config.php approach would be the most reliable.
 
Back
Top Bottom