Checked on local project, the error occurs when License Expiraton is not set.
Code works as intended.
lucian_pana → created an issue.
Another thing you can check is if you have a development.services.yml - In my case, it was here where I found a debug config for twig to be set to true. Make sure to set it there to false as well.