feature #14192 [HttpKernel] Embed the original exception as previous to bounced exceptions (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[HttpKernel] Embed the original exception as previous to bounced exceptions
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #14073
| License | MIT
| Doc PR | -
Commits
-------
bb020f4
[HttpKernel] Embed the original exception as previous to bounced exceptions
This commit is contained in:
commit
3c2c5c90a0
@ -62,7 +62,18 @@ class ExceptionListener implements EventSubscriberInterface
|
|||||||
// set handling to false otherwise it wont be able to handle further more
|
// set handling to false otherwise it wont be able to handle further more
|
||||||
$handling = false;
|
$handling = false;
|
||||||
|
|
||||||
// throwing $e, not $exception, is on purpose: fixing error handling code paths is the most important
|
$wrapper = $e;
|
||||||
|
|
||||||
|
while ($prev = $wrapper->getPrevious()) {
|
||||||
|
if ($exception === $wrapper = $prev) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$prev = new \ReflectionProperty('Exception', 'previous');
|
||||||
|
$prev->setAccessible(true);
|
||||||
|
$prev->setValue($wrapper, $exception);
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->fail('RuntimeException expected');
|
$this->fail('RuntimeException expected');
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
$this->assertSame('bar', $e->getMessage());
|
$this->assertSame('bar', $e->getMessage());
|
||||||
|
$this->assertSame('foo', $e->getPrevious()->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +78,7 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->fail('RuntimeException expected');
|
$this->fail('RuntimeException expected');
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
$this->assertSame('bar', $e->getMessage());
|
$this->assertSame('bar', $e->getMessage());
|
||||||
|
$this->assertSame('foo', $e->getPrevious()->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals(3, $logger->countErrors());
|
$this->assertEquals(3, $logger->countErrors());
|
||||||
|
Reference in New Issue
Block a user