stefandoorn / sitemap-plugin

Sitemap Plugin for Sylius eCommerce platform
MIT License
79 stars 45 forks source link

Issue with routing when we make a mistake in our own app #75

Open jacquesbh opened 5 years ago

jacquesbh commented 5 years ago

Hi!

In your routing you have:

sylius_sitemap_providers:
    resource: .
    type: sitemap

This causes a problem when we make a mistake in our own routing. If so, it returns always this error:

Exception thrown when handling an exception (Symfony\Component\Config\Exception\LoaderLoadException: Do not add the "sitemap" loader twice in . (which is being imported from "/sylius/vendor/stefandoorn/sitemap-plugin/src/Resources/config/routing.yml"). Make sure there is a loader supporting the "sitemap" type.)

If we comment out the route configuration above, we get the correct error: (as example, in my case)

Exception thrown when handling an exception (Symfony\Component\Config\Exception\LoaderLoadException: The routing file "/sylius/config/routes.yaml" must not specify both the "resource" key and the "path" key for "app_custom". Choose between an import and a route definition in /sylius/config/routes.yaml (which is loaded in resource "/sylius/config/routes.yaml").)

And this is the same issue everytime we make an error in our config. This is kind of very annoying actually.

Can we try to find a solution to avoid this behavior? What do you think?

Thanks!

How to reproduce

Of course with the sitemap bundle loaded.

In your config/routes.yaml, add these lines:

example:
    resource: "toto.yaml"

Do not create the toto.yaml file.

Reload and you'll get the error …Do not add the "sitemap" loader twice in….

Now, comment the lines in the routing of the bundle like written above in the description. Reload and you get this error: …The file "toto.yaml" does not exist…

This is much better don't you think? Thanks!

stefandoorn commented 5 years ago

Thanks @jacquesbh. I've been looking through this, but I find it hard to figure out what is the issue here. I've also reverted to the Symfony docs, and basically it's following the suggestions there: https://symfony.com/doc/current/routing/custom_route_loader.html#using-the-custom-loader. I'm a bit lost where the error is coming from therefore.

stefandoorn commented 5 years ago

@jacquesbh Could you try removing the Exception and letting it load twice? I'm curious what happens to the routing table and performance if the router get's executed twice. Alternative is to see in case it's already loaded, to just return an empty RouteCollection.