wildnano
wildnano

Reputation: 21

symfony services.yml does not contain valid YAML

I get an error in my services.yml : services.yml does not contain valid YAML Symfony 3

redirectionListener:
  class: Gba\GbaBundle\Listener\RedirectionListener
  arguments: [@service_container, @session] 
  tags:
    - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }   

Can you help me

Thanks

Screenshot:

enter image description here

Upvotes: 1

Views: 12704

Answers (4)

alakin_11
alakin_11

Reputation: 719

I linted my yml on this website. Helped me find the error ASAP.

https://yamlchecker.com/

Upvotes: 1

Christopher Hamkins
Christopher Hamkins

Reputation: 1639

In my case it was due to having blanks at the end of the line after the } symbol.

Upvotes: 0

Massetho
Massetho

Reputation: 1

I had this error once. It was because I didn't let a blank line at the end of my services.yaml file. Once I did so, no more errors !

Upvotes: 0

dbrumann
dbrumann

Reputation: 17166

There are some restrictions in yaml you have to be aware of. Symfony has a neat command line tool you can use to check if a yaml file is valid that will also try to point you to where the error lies. You can run it like this:

bin/console yaml:lint src/Gba/GbaBundle/Resources/config/services.yml

This will only do the lint on this one file you can also point it to a whole directory of files if you want.

My best guess is, that you have to put quotes around the services defined as arguments and in fact I prefer to quote every string value in yaml:

redirectionListener:
  class: 'Gba\GbaBundle\Listener\RedirectionListener'
  arguments: ['@service_container', '@session'] 
  tags:
    - { name: 'kernel.event_listener', event: 'kernel.request', method: 'onKernelRequest' }

Other things to look out for in yaml is correct indentation and mixing spaces & tabs.

Upvotes: 5

Related Questions