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

Some error's do not log. #568

Open
Open

Description

@maxkain

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);
        }
    }
}

Activity

  1. changed the title [-]Some error's logs do not log.[/-] [+]Some error's do not log.[/+] on Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions