Git Product home page Git Product logo

handlebars-error-parser's Introduction

handlebars-error-parser

The purpose of this module is to parse the Handlebars compile exceptions messages into a more useable format which can be used in handlebars linter(s). Handlebars throws different exceptions depending the template error.

Handlebars exception types:

  • Parser Error: handlebars can't compile the template.
  • Block Error: the open and close block helpers do not match.

This module parses the exception message into:

{
    minLine: 1,
    minColumn: 3,
    maxLine: 1,
    maxColumn: 4,
    message: 'foo doesn\'t match bar'
}

Install

npm install handlebars-error-parser --save

In Node.js:

var parser = require('handlebars-error-parser').parser;
var html = '{{#foo}}{{/bar}}';
var parsed;
try {
    hbs.precompile(html);
} catch (e) {
    parsed = parser(e, html);
}

In browser:

<script src="./node_modules/handlebars-error-parser/index.js"></script>
var html = '{{#foo}}{{/bar}}';
var parsed;
try {
    hbs.precompile(html);
} catch (e) {
    parsed = window.HandlebarsErrorParser(e, html);
}

Block Error: Mismatched: block helpers

{{#foo}}{{/bar}}
foo doesn't match bar - 1:3

Block Error: Mismatached: closing helpler

{{foo}}{{/foo}}
Parse error on line 1:
{{foo}}{{/foo}}
-------^
Expecting 'EOF', got 'OPEN_ENDBLOCK'

Parse Error: Missing helper or variable closing

{{foo
Parse error on line 1:
{{foo
--^
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID'

Parse Error: Missing block helper closing

{{#foo
Parse error on line 1:
{{#foo
---^
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID'

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.