Skip to content

Confusing error message: 'must define the "event" attribute on "kernel.event_listener" tags' when the problem was nonexistent class #54095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
php4fan opened this issue Feb 27, 2024 · 7 comments · May be fixed by #60277
Labels
Bug DependencyInjection Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Needs Review

Comments

@php4fan
Copy link

php4fan commented Feb 27, 2024

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

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@php4fan
Copy link
Author

php4fan commented Aug 29, 2024

There has not been a lot of activity here for a while

Indeed. Actually, there hasn't been any activity ever. Maybe time to look into it?

Is this bug still relevant?

I don't know. Have you done anything to fix it? If not, it almost certainly is still relevant

@carsonbot carsonbot removed the Stalled label Aug 29, 2024
@xabbuh
Copy link
Member

xabbuh commented Aug 30, 2024

Indeed. Actually, there hasn't been any activity ever. Maybe time to look into it?

@php4fan Would you like to look into how to potentially fix this?

@php4fan
Copy link
Author

php4fan commented Aug 30, 2024

I'd love to but I don't think I have that much free time unfortunately.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@chalasr chalasr added Help wanted Issues and PRs which are looking for volunteers to complete them. and removed Stalled labels Mar 1, 2025
@php4fan
Copy link
Author

php4fan commented Mar 5, 2025

Issue still exists on Symfony 7.2.4, nothing has changed.

@ashutoshagrawal1010
Copy link

ashutoshagrawal1010 commented Apr 28, 2025

#60277 to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DependencyInjection Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Needs Review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants