Skip to content

[DX] Misleading error when the namespace of a controller is wrong #14073

Closed
@javiereguiluz

Description

@javiereguiluz

The problem

The other day I was playing with the Symfony Demo application, in which the routing is simply defined as:

# app/config/routing.yml
app:
    resource: @AppBundle/Controller/
    type:     annotation

I had a BlogController.php file with @Route() annotations in src/AppBundle/Controller/BlogController.php file.

Then, I moved this controller to the src/AppBundle/Controller/Admin/ folder without updating the namespace of the PHP class. Then, the application displayed the following error message:

FileLoaderImportCircularReferenceException in FileLoader.php line 97:
Circular reference detected in "/Users/javier/sf/symfony-demo/app/config/routing_dev.yml" 
("/Users/javier/sf/symfony-demo/app/config/routing_dev.yml" >
"/Users/javier/sf/symfony-demo/app/config/routing.yml" >
"/Users/javier/sf/symfony-demo/src/AppBundle/Controller/" >
"/Users/javier/sf/symfony-demo/app/config/routing_dev.yml").

Sadly this error message is very misleading because CircularReferenceException message looks scary and the error keeps talking about the routing_dev.yml file, which has nothing to do with the actual error.

The solution

Symfony already includes some great error messages when you are warned about typos and PHP classes mislocations. I'd like to see a better error message when the namespace of a controller file is not correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions