GithubHelp home page GithubHelp logo

nataliecarey / nunjucks-error-example Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 12 KB

An example of Nunjucks reporting errors against the wrong lines

JavaScript 27.92% Nunjucks 13.23% HTML 58.85%

nunjucks-error-example's Introduction

Nunjucks error reporting issue

Short version

Inserting the line {{ "testing" | thisFilterDoesNotExist }} to views/index.html 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.

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 [email protected]: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.

nunjucks-error-example's People

Contributors

nataliecarey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.