Description
Symfony version(s) affected
5.4
Description
I followed this guide:
https://symfony.com/doc/5.x/event_dispatcher.html
and I created a class App\Listeners\ExceptionListener.php
but in services.yaml
I mistyped the class name as:
services:
App\Listener\ExceptionListener:
tags: [kernel.event_listener]
Note the namespace Listener
without the s
.
I got this confusing error:
Service "App\Listener\ExceptionListener" must define the "event" attribute on "kernel.event_listener" tags.
which didn't help much, because I was becoming stupid trying to figure out why it complained about a missing attribute that should be optional.
Until I figured out I had misspelled the namespace. To the error message's credit, it does repeat the name of the class, so that gives an opportunity to catch it (which I missed), but still, the error message is unnecessarily misleading. It's specifically directing my attention to a place where the issue is not.
The error should have said something like: "Service App\Listener\ExceptionListener
does not exist." (and if it can add a "Did you mean one of the following...?" that would be great).
How to reproduce
In services.yaml
, add:
services:
App\Some\NonExistentListener:
tags: [kernel.event_listener]
Possible Solution
No response
Additional Context
No response