8000 [HttpKernel] Embed the original exception as previous to bounced exce… · symfony/symfony@bb020f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb020f4

Browse files
[HttpKernel] Embed the original exception as previous to bounced exceptions
1 parent 40a350b commit bb020f4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ public function onKernelException(GetResponseForExceptionEvent $event)
6262
// set handling to false otherwise it wont be able to handle further more
6363
$handling = false;
6464

65-
// throwing $e, not $exception, is on purpose: fixing error handling code paths is the most important
65+
$wrapper = $e;
66+
67+
while ($prev = $wrapper->getPrevious()) {
68+
if ($exception === $wrapper = $prev) {
69+
throw $e;
70+
}
71+
}
72+
73+
$prev = new \ReflectionProperty('Exception', 'previous');
74+
$prev->setAccessible(true);
75+
$prev->setValue($wrapper, $exception);
76+
6677
throw $e;
6778
}
6879

src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function testHandleWithoutLogger($event, $event2)
5757
$this->fail('RuntimeException expected');
5858
} catch (\RuntimeException $e) {
5959
$this->assertSame('bar', $e->getMessage());
60+
$this->assertSame('foo', $e->getPrevious()->getMessage());
6061
}
6162
}
6263

@@ -77,6 +78,7 @@ public function testHandleWithLogger($event, $event2)
7778
$this->fail('RuntimeException expected');
7879
} catch (\RuntimeException $e) {
7980
$this->assertSame('bar', $e->getMessage());
81+
$this->assertSame('foo', $e->getPrevious()->getMessage());
8082
}
8183

8284
$this->assertEquals(3, $logger->countErrors());

0 commit comments

Comments
 (0)
0