Reputation: 135
Is there any way to debug swig template engine for node.js, because I don't get the exact file in which the error occurred in some cases, e.g.
{% set temp = JSON.parse('some random string') %}
This what I get in console for above:
2015-08-13T09:38:12.254Z - error: SyntaxError: Unexpected token s
at Object.parse (native)
at Object.eval [as tpl] (eval at <anonymous> (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:498:13), <anonymous>:6:810)
at compiled (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:619:18)
at Object.eval [as tpl] (eval at <anonymous> (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:498:13), <anonymous>:27:611)
at compiled (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:619:18)
at /home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:559:20
at /home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:690:9
at fs.js:268:14
at Object.oncomplete (fs.js:107:15)
There is no mention of the template file in which error occurred.
Upvotes: 2
Views: 662
Reputation: 14590
EDITED: You are right, the problem is 'some random string', you can't JSON.parse
a string isn't a JSON.
So you should have something like this:
{% set temp = JSON.parse('{"test": true}') %}
Upvotes: 1