Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unwrap errors in FlattenException #26028

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

Merged
merged 1 commit into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions 14 src/Symfony/Component/Debug/Exception/FatalThrowableError.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
*/
class FatalThrowableError extends FatalErrorException
{
private $originalClassName;

public function __construct(\Throwable $e)
{
$this->originalClassName = \get_class($e);

if ($e instanceof \ParseError) {
$message = 'Parse error: '.$e->getMessage();
$severity = E_PARSE;
} elseif ($e instanceof \TypeError) {
$message = 'Type error: '.$e->getMessage();
$severity = E_RECOVERABLE_ERROR;
} else {
$message = $e->getMessage();
$severity = E_ERROR;
}

\ErrorException::__construct(
$message,
$e->getMessage(),
$e->getCode(),
$severity,
$e->getFile(),
Expand All @@ -41,4 +42,9 @@ public function __construct(\Throwable $e)

$this->setTrace($e->getTrace());
}

public function getOriginalClassName(): string
{
return $this->originalClassName;
}
}
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Debug/Exception/FlattenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function create(\Exception $exception, $statusCode = null, array $
$e->setStatusCode($statusCode);
$e->setHeaders($headers);
$e->setTraceFromException($exception);
$e->setClass(get_class($exception));
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
$e->setFile($exception->getFile());
$e->setLine($exception->getLine());

Expand Down Expand Up @@ -157,7 +157,7 @@ public function getPrevious()
return $this->previous;
}

public function setPrevious(FlattenException $previous)
public function setPrevious(self $previous)
{
$this->previous = $previous;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Debug\Tests\Exception;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand Down Expand Up @@ -123,6 +124,16 @@ public function testFlattenHttpException(\Exception $exception)
$this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
}

public function testThrowable()
{
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
$flattened = FlattenException::create($exception);

$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
$this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
}

/**
* @dataProvider flattenDataProvider
*/
Expand All @@ -144,9 +155,9 @@ public function testPreviousError()

$flattened = FlattenException::create($exception)->getPrevious();

$this->assertEquals($flattened->getMessage(), 'Parse error: Oh noes!', 'The message is copied from the original exception.');
$this->assertEquals($flattened->getMessage(), 'Oh noes!', 'The message is copied from the original exception.');
$this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
$this->assertEquals($flattened->getClass(), 'Symfony\Component\Debug\Exception\FatalThrowableError', 'The class is set to the class of the original exception');
$this->assertEquals($flattened->getClass(), 'ParseError', 'The class is set to the class of the original exception');
}

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.