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

Commit f14d7d6

Browse filesBrowse files
committed
Unwrap errors in FlattenException.
1 parent 7a461cf commit f14d7d6
Copy full SHA for f14d7d6

File tree

3 files changed

+25
-8
lines changed
Filter options

3 files changed

+25
-8
lines changed

‎src/Symfony/Component/Debug/Exception/FatalThrowableError.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Exception/FatalThrowableError.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@
1818
*/
1919
class FatalThrowableError extends FatalErrorException
2020
{
21+
private $originalClassName;
22+
2123
public function __construct(\Throwable $e)
2224
{
25+
$this->originalClassName = \get_class($e);
26+
2327
if ($e instanceof \ParseError) {
24-
$message = 'Parse error: '.$e->getMessage();
2528
$severity = E_PARSE;
2629
} elseif ($e instanceof \TypeError) {
27-
$message = 'Type error: '.$e->getMessage();
2830
$severity = E_RECOVERABLE_ERROR;
2931
} else {
30-
$message = $e->getMessage();
3132
$severity = E_ERROR;
3233
}
3334

3435
\ErrorException::__construct(
35-
$message,
36+
$e->getMessage(),
3637
$e->getCode(),
3738
$severity,
3839
$e->getFile(),
@@ -41,4 +42,9 @@ public function __construct(\Throwable $e)
4142

4243
$this->setTrace($e->getTrace());
4344
}
45+
46+
public function getOriginalClassName(): string
47+
{
48+
return $this->originalClassName;
49+
}
4450
}

‎src/Symfony/Component/Debug/Exception/FlattenException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Exception/FlattenException.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function create(\Exception $exception, $statusCode = null, array $
5353
$e->setStatusCode($statusCode);
5454
$e->setHeaders($headers);
5555
$e->setTraceFromException($exception);
56-
$e->setClass(get_class($exception));
56+
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
5757
$e->setFile($exception->getFile());
5858
$e->setLine($exception->getLine());
5959

@@ -157,7 +157,7 @@ public function getPrevious()
157157
return $this->previous;
158158
}
159159

160-
public function setPrevious(FlattenException $previous)
160+
public function setPrevious(self $previous)
161161
{
162162
$this->previous = $previous;
163163
}

‎src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Debug\Tests\Exception;
1313

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

127+
public function testThrowable()
128+
{
129+
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
130+
$flattened = FlattenException::create($exception);
131+
132+
$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
133+
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
134+
$this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
135+
}
136+
126137
/**
127138
* @dataProvider flattenDataProvider
128139
*/
@@ -144,9 +155,9 @@ public function testPreviousError()
144155

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

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

152163
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.