Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Some error's do not log. #568

Open
maxkain opened this issue Dec 29, 2021 · 0 comments
Open

Some error's do not log. #568

maxkain opened this issue Dec 29, 2021 · 0 comments
Assignees
Labels
kind/bug/possible Something probably isn't working priority/important

Comments

@maxkain
Copy link

maxkain commented Dec 29, 2021

Maybe it is Symfony issue, but it works fine with php-fpm or APP_DEV for unknown reasons.

Some errors are not hanled, messages disappear, for example php type error of function argument or using null as object.
I fixed it by decorating Symfony HttpKernel, it catches only \Exception, but not \Throwable:

services.yaml

    App\Service\HttpKernel\HttpKernel:
        parent: http_kernel
        decorates: http_kernel

App\Service\HttpKernel\HttpKernel

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernel as BaseHttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class HttpKernel extends BaseHttpKernel
{
    public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true)
    {
        try {
            return parent::handle($request, $type, $catch);
        } catch (\Throwable $e) {
            $ref = (new \ReflectionObject($this))->getParentClass();

            if (false === $catch) {
                $finishRequest = $ref->getMethod('finishRequest');
                $finishRequest->setAccessible(true);

                $finishRequest->invoke($this, $request, $type);

                throw $e;
            }

            $handleThrowable = $ref->getMethod('handleThrowable');
            $handleThrowable->setAccessible(true);

            return $handleThrowable->invoke($this, $e, $request, $type);
        }
    }
}
@maxkain maxkain added kind/bug/possible Something probably isn't working priority/important labels Dec 29, 2021
@maxkain maxkain changed the title Some error's logs do not log. Some error's do not log. Dec 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug/possible Something probably isn't working priority/important
Projects
None yet
Development

No branches or pull requests

2 participants