Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@php4fan

Description

@php4fan
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.