Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors thrown for an invalid parent don't report their file and line as the Twig template #3266

Closed
stof opened this issue Feb 12, 2020 · 4 comments · Fixed by #4583
Closed

Comments

@stof
Copy link
Member

stof commented Feb 12, 2020

See the fiddle at https://twigfiddle.com/hmgy4z

The template name and the line are reported as part of the message, not as part of the exception location, as done for most other Twig errors (and so the Symfony error page would not extract a code snippet from the Twig file).

The cause is that the location is set by using \Twig\Template::loadTemplate in the compile code (see the compilation logic) but that method takes only a template name, not a source context. And when it builds a source context from it, it cannot give it a source path, even if the template had the info.

A suggestion to fix that would be to change \Twig\Template::loadTemplate to accept a SourceContext rather than a template name (we might support both if needed) for cases which have it (most places now, as the compiled code always extract the name from the source context anyway).

@fabpot
Copy link
Contributor

fabpot commented Feb 27, 2020

@stof Would you like to submit a PR?

@stof
Copy link
Member Author

stof commented Feb 28, 2020

@fabpot I'll do it.

@fabpot
Copy link
Contributor

fabpot commented Sep 24, 2024

@stof By any chance, can you have a look at this one?

@fabpot
Copy link
Contributor

fabpot commented Feb 14, 2025

@stof See #4583

@fabpot fabpot closed this as completed in ad203c7 Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants