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 report the wrong line number. #1429

Open
nataliecarey opened this issue Jan 16, 2023 · 0 comments
Open

Errors report the wrong line number. #1429

nataliecarey opened this issue Jan 16, 2023 · 0 comments

Comments

@nataliecarey
Copy link

Nunjucks error reporting issue

Short version

There is an issue with the reported line number when a filter is not found (and maybe other cases) inside a block.

I created an example on Github.

Inserting the line {{ "testing" | thisFilterDoesNotExist }} into views/index.html in this example reports the wrong line number. Generally Nunjucks will report the line above {% block %} declaration that the erroring line is contained within. If it's after an include Nunjucks will report the include as the problem. This can be replicated by inserting it as lines 5, 7, 15, 17 and 19.

I hope to raise a PR.

Long version

I work on the GOV.UK Prototype Kit team, we provide a tool for users with a whole range of technical abilities. We use Nunjucks with Express.

While investigating how to nicely present errors to our users and we realised that Nunjucks incorrectly reports line numbers in some circumstances. This is repeatable so I created an example on Github.

Before recreating the issue clone the project and make sure everything is running using:

git clone git@github.com:nataliecarey/nunjucks-error-example.git
cd nunjucks-error-example
npm install
npm start

Then follow the URL that is shown in the terminal.

You should see a page with two sections and plenty of Lorum Ipsum placeholder text.

Now it's time to break it.

Add the following line to different parts of views/index.html and look at the line number that the error is reported on:

{{ "testing" | thisFilterDoesNotExist }}
  • If we add it on line 5 it says the error occurred on line 2.
  • If we add it on line 7 it still says the error occurred on line 2.
  • If we add it on line 15 it says the error occurred on line 12.
  • If we add it on line 17 it still says the error occurred on line 12.

It becomes more interesting when we get further down.

  • If we add it on line 19 it says the error occurred inside the include (which was included on line 18).
  • If we add it on line 21 it still says the error occurred inside the include.

When we try to highlight the line on which the error occurred we're pointing the user in the wrong direction. This comes from a bug inside Nunjucks which I hope to raise a fix for.

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

No branches or pull requests

1 participant