8000 Debug exception classes fail to pass $previous to FatalErrorException · Issue #27483 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Debug exception classes fail to pass $previous to FatalErrorException #27483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alreece45 opened this issue Jun 4, 2018 · 6 comments
Closed

Comments

@alreece45
Copy link
alreece45 commented Jun 4, 2018

Symfony version(s) affected: 4.1.2 (appears to affect 4.1.0)

Description

Debug exceptions pass an invalid parameter when $previous is set. e.g:

Uncaught TypeError: Argument 6 passed to Symfony\Component\Debug\Exception\FatalErrorException::__construct() must be of the type integer or null, object given,

Classes that appear to be affected:

How to reproduce
Trigger an undefined method, class, or function with another exception.

Possible Solution

  1. Accept an object as the 6th parameter (BC issue?)
  2. Don't pass $previous to the FatalErrorException constructor (potentially use a setter?)
@xabbuh
Copy link
Member
xabbuh commented Jun 4, 2018

Can you create a small example application that allows to reproduce your issue?

@alreece45
Copy link
Author
alreece45 commented Jun 4, 2018

I was hoping it'd be obvious enough that $previous is not an integer.

Below is an example controller that contains routes that trigger an error in each one of the classes:

<?php

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class BugController extends Controller
{
    /**
     * @Route("/bug/method")
     */
    public function me()
    {
        try {
            throw new \RuntimeException("This exception doesn't matter much");
        } finally {
            $a = new \stdClass();
            $a->undefinedMethod();
        }
    }
    /**
     * @Route("/bug/function")
     */
    public function fu()
    {
        try {
            throw new \RuntimeException("This exception doesn't matter much");
        } finally {
            undefined_function();
        }
    }
    /**
     * @Route("/bug/class")
     */
    public function cl()
    {
        try {
            throw new \RuntimeException("This exception doesn't matter much");
        } finally {
            $a = new UndefinedClass();
        }
    }
}

@pmontoya
Copy link
pmontoya commented Jun 5, 2018

Can I take this one?

@pmontoya
Copy link
pmontoya commented Jun 5, 2018

My suggestion

  • Add a parameter to Symfony\Component\Debug\Exception\FatalErrorException constructor with default value null
  • Call \ErrorException with this parameter.
  • Call parent constructor of classes that extend FatalErrorException with default parameters followed by $previous :
parent::__construct(
    $message,
    $previous->getCode(),
    $previous->getSeverity(),
    $previous->getFile(),
    $previous->getLine(),
    null,
    true,
    null,
    $previous->getPrevious()
);

Is it ok for you?

@xabbuh
Copy link
Member
xabbuh commented Jun 5, 2018

@pmontoya Sounds reasonable to me, would you like to create a PR?

@pmontoya
Copy link
pmontoya commented Jun 6, 2018

@xabbuh : The bug exists in 2.8 but type hint error in 4.0. On which branch I create the fix please?

fabpot added a commit that referenced this issue Jun 6, 2018
…ontoya)

This PR was merged into the 2.8 branch.

Discussion
----------

[Debug] Pass previous exception to FatalErrorException

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27483
| License       | MIT

Add a previous parameter to FatalErrorException.
Call \ErrorException with this parameter.
Update parent::__constructor for inherited classes with default parameters and the new one

Commits
-------

7f9780b Pass previous exception to FatalErrorException
@fabpot fabpot closed this as completed Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0