Skip to content

Commit 40ab7ef

Browse files
[HttpKernel] Embed the original exception as previous to bounced exceptions
1 parent 7dca9a9 commit 40ab7ef

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
@@ -72,7 +72,18 @@ public function onKernelException(GetResponseForExceptionEvent $event)
7272
// set handling to false otherwise it wont be able to handle further more
7373
$handling = false;
7474

75-
// throwing $e, not $exception, is on purpose: fixing error handling code paths is the most important
75+
$wrapper = $e;
76+
77+
while ($prev = $wrapper->getPrevious()) {
78+
if ($exception === $wrapper = $prev) {
79+
throw $e;
80+
}
81+
}
82+
83+
$prev = new \ReflectionProperty('Exception', 'previous');
84+
$prev->setAccessible(true);
85+
$prev->setValue($wrapper, $exception);
86+
7687
throw $e;
7788
}
7889

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)