handlebars-error-parser

1.0.9 • Public • Published

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'

Readme

Keywords

none

Package Sidebar

Install

npm i handlebars-error-parser

Weekly Downloads

21

Version

1.0.9

License

MIT

Unpacked Size

11.9 kB

Total Files

7

Last publish

Collaborators

  • dhollenbeck