8000 [2.7] Fixed flatten exception recursion with errors · symfony/symfony@2b0721d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b0721d

Browse files
GrahamCampbellfabpot
authored andcommitted
[2.7] Fixed flatten exception recursion with errors
1 parent 021ab8a commit 2b0721d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ public static function create(\Exception $exception, $statusCode = null, array $
9494
$e->setClass(get_class($exception));
9595
$e->setFile($exception->getFile());
9696
$e->setLine($exception->getLine());
97-
if ($exception->getPrevious()) {
98-
$e->setPrevious(static::create($exception->getPrevious()));
97+
98+
$previous = $exception->getPrevious();
99+
100+
if ($previous instanceof \Exception) {
101+
$e->setPrevious(static::create($previous));
102+
} elseif ($previous instanceof \Throwable) {
103+
$e->setPrevious(static::create(new FatalThrowableError($previous)));
99104
}
100105

101106
return $e;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ public function testPrevious(\Exception $exception, $statusCode)
131131
$this->assertSame(array($flattened2), $flattened->getAllPrevious());
132132
}
133133

134+
/**
135+
* @requires PHP 7.0
136+
*/
137+
public function testPreviousError()
138+
{
139+
$exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));
140+
141+
$flattened = FlattenException::create($exception)->getPrevious();
142+
143+
$this->assertEquals($flattened->getMessage(), 'Parse error: Oh noes!', 'The message is copied from the original exception.');
144+
$this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
145+
$this->assertEquals($flattened->getClass(), 'Symfony\Component\Debug\Exception\FatalThrowableError', 'The class is set to the class of the original exception');
146+
}
147+
134148
/**
135149
* @dataProvider flattenDataProvider
136150
*/

0 commit comments

Comments
 (0)
0