Skip to content

Commit 73f6c16

Browse files
committed
bug symfony#10564 fixed the profiler when an uncalled listener throws an exception when instantiated (fabpot)
This PR was merged into the 2.3 branch. Discussion ---------- fixed the profiler when an uncalled listener throws an exception when instantiated | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#10371 | License | MIT | Doc PR | n/a When the profiler gets the uncalled listeners, the current page is broken without a very clear message. That happens when a listener is a service that depends for instance on the request; creating this service throws an exception. After this patch, if we cannot get the listeners, we give up and add a log message about the problem (the error message is an info as the problem is not really related to the toolbar but more about how things work). Commits ------- 79540d4 fixed the profiler when an uncalled listener throws an exception when instantiated
2 parents 8a19b9a + 79540d4 commit 73f6c16

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
{% endfor %}
3737
</table>
3838

39-
{% if collector.notcalledlisteners %}
40-
<h2>Not Called Listeners</h2>
39+
<h2>Not Called Listeners</h2>
4140

41+
{% if collector.notcalledlisteners %}
4242
<table>
4343
<tr>
4444
<th>Event name</th>
@@ -52,6 +52,17 @@
5252
</tr>
5353
{% endfor %}
5454
</table>
55+
{% else %}
56+
<p>
57+
<strong>No uncalled listeners</strong>.
58+
</p>
59+
<p>
60+
61+
All listeners were called for this request or an error occurred
62+
when trying to collect uncalled listeners (in which case check the
63+
logs to get more information).
64+
65+
</p>
5566
{% endif %}
5667
{% endblock %}
5768

src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,19 @@ public function getCalledListeners()
160160
*/
161161
public function getNotCalledListeners()
162162
{
163-
$notCalled = array();
163+
try {
164+
$allListeners = $this->getListeners();
165+
} catch (\Exception $e) {
166+
if (null !== $this->logger) {
167+
$this->logger->info(sprintf('An exception was thrown while getting the uncalled listeners (%s)', $e->getMessage()), array('exception' => $e));
168+
}
164169

165-
foreach ($this->getListeners() as $name => $listeners) {
170+
// unable to retrieve the uncalled listeners
171+
return array();
172+
}
173+
174+
$notCalled = array();
175+
foreach ($allListeners as $name => $listeners) {
166176
foreach ($listeners as $listener) {
167177
$info = $this->getListenerInfo($listener, null, $name);
168178
if (!isset($this->called[$name.'.'.$info['pretty']])) {

0 commit comments

Comments
 (0)