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

Add file and line to error message #3798

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from

Conversation

ctippler
Copy link

When an error occures we currently get the message e.g.
"An exception has been thrown during the rendering of a template ("Warning: Undefined array key "select"")."

The problem is, that we don't know in which file and where the error occured so it is very hard to find the "cause" of the problem.
If we add the File and Line it is quite easy to find the problem:

image

@fabpot
Copy link
Contributor

fabpot commented Dec 31, 2022

Can you give a Twig template that exhibits the issue? This PR does not work as you can see in the tests.

@ctippler
Copy link
Author

ctippler commented Jan 1, 2023

In my case this happens when i call e.g. a twig function and in the twig function i access a undefined array key.

As an example:
The view:

{{  "test" | trans }}

{{ app_formatter_test(123)}}

The Twig extension looks like this:

    /**
     * @return \Twig\TwigFunction[]
     */
    public function getFunctions(): array
    {
        return [
            new TwigFunction('app_formatter_test', [$this, 'test'], ['is_safe' => ['html']]),
        ];
    }

    public function test($number) : string
    {

        $x = [];
        $y = $x['asdf']; //this causes the warning/error
        return $number;
    }

image

The twig function is just an example - normaly i have this issue with calls to more complex data models where it is realy hard to find the cause.

Regards,
Christian

@fabpot
Copy link
Contributor

fabpot commented Jan 11, 2024

The example you gave me emits a warning, which is not cause by Twig. The error message given by PHP gives you the file and line number where it happens, so probably not a good example (at least not one I can use to understand your real-wprld issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants