When you do some error inside the template, the errors indicate exactly where the issue -> awesome
Template render error: (/sandbox/views/index.html) [Line 10, Column 7]
unexpected token: |
at Object._prettifyError (/sandbox/node_modules/nunjucks/src/lib.js:36:11)
at Template.render (/sandbox/node_modules/nunjucks/src/environment.js:542:21)
at /sandbox/node_modules/nunjucks/src/environment.js:366:27
at createTemplate (/sandbox/node_modules/nunjucks/src/environment.js:315:9)
at handle (/sandbox/node_modules/nunjucks/src/environment.js:327:11)
at /sandbox/node_modules/nunjucks/src/environment.js:339:9
at next (/sandbox/node_modules/nunjucks/src/lib.js:280:7)
at Object.asyncIter (/sandbox/node_modules/nunjucks/src/lib.js:286:3)
at Environment.getTemplate (/sandbox/node_modules/nunjucks/src/environment.js:321:9)
at Environment.render (/sandbox/node_modules/nunjucks/src/environment.js:360:10)
When you do some error inside the custom filter, the errors only mention that the issue is in some template, you do not get a place of error in the template, you do not get any information in what filter the issue happened
Template render error: (/sandbox/views/index.html)
ReferenceError: ddd is not defined
at Object._prettifyError (/sandbox/node_modules/nunjucks/src/lib.js:36:11)
at /sandbox/node_modules/nunjucks/src/environment.js:567:19
at eval (eval at _compile (/sandbox/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:12:11)
at /sandbox/node_modules/nunjucks/src/environment.js:617:9
at Template.root [as rootRenderFunc] (eval at _compile (/sandbox/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:76:3)
at Template.getExported (/sandbox/node_modules/nunjucks/src/environment.js:615:10)
at eval (eval at _compile (/sandbox/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:11:5)
at createTemplate (/sandbox/node_modules/nunjucks/src/environment.js:315:9)
at handle (/sandbox/node_modules/nunjucks/src/environment.js:327:11)
at /sandbox/node_modules/nunjucks/src/environment.js:339:9
Debugging such errors is a challenge. Luckily you have a hidden config feature (I mean hidden as not documented) that you enable like this dev: true that improves debugging of filters but then again debugging of templates gets worse. Example of errors of the same errors I caused above:
Template error:
Error: unexpected token: |
at new TemplateError (/sandbox/node_modules/nunjucks/src/lib.js:89:17)
at Parser.error (/sandbox/node_modules/nunjucks/src/parser.js:84:12)
at Parser.parsePrimary (/sandbox/node_modules/nunjucks/src/parser.js:1010:18)
at Parser.parseUnary (/sandbox/node_modules/nunjucks/src/parser.js:955:19)
at Parser.parsePow (/sandbox/node_modules/nunjucks/src/parser.js:936:21)
at Parser.parseMod (/sandbox/node_modules/nunjucks/src/parser.js:925:21)
at Parser.parseFloorDiv (/sandbox/node_modules/nunjucks/src/parser.js:914:21)
at Parser.parseDiv (/sandbox/node_modules/nunjucks/src/parser.js:903:21)
at Parser.parseMul (/sandbox/node_modules/nunjucks/src/parser.js:892:21)
at Parser.parseSub (/sandbox/node_modules/nunjucks/src/parser.js:881:21)
Filter error -> awesome
ReferenceError: ddd is not defined
at Context.replaceVariablesWithValues (/sandbox/src/filters.js:9:3)
at eval (eval at _compile (/sandbox/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:76:151)
at /sandbox/node_modules/nunjucks/src/environment.js:619:9
at Template.root [as rootRenderFunc] (eval at _compile (/sandbox/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:72:1)
at Template.getExported (/sandbox/node_modules/nunjucks/src/environment.js:615:10)
at eval (eval at _compile (/sandbox/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:11:5)
at createTemplate (/sandbox/node_modules/nunjucks/src/environment.js:315:9)
at handle (/sandbox/node_modules/nunjucks/src/environment.js:327:11)
at /sandbox/node_modules/nunjucks/src/environment.js:339:9
at next (/sandbox/node_modules/nunjucks/src/lib.js:280:7)
I have this sandbox project where I play with Nunjucks functionality. I used it to quickly generate the above errors.
Questions
First of all, do you know why it is happening like this? any ideas already on how to improve. Of course, the best would be to combine both awesome examples from above, but I have a feeling that it might not be possible and this is why you added the dev flag. This is the only way I explain to myself why it is done now like this. Thoughts?
I know I can explicitly add try-catch to my filter to get errors related to custom filters without a dev flag to also keep good errors for templates, but doing it with each filter seems cumbersome. Any opinions would be appreciated.
Context
Debugging such errors is a challenge. Luckily you have a hidden config feature (I mean hidden as not documented) that you enable like this
dev: true
that improves debugging of filters but then again debugging of templates gets worse. Example of errors of the same errors I caused above:I have this sandbox project where I play with Nunjucks functionality. I used it to quickly generate the above errors.
Questions
First of all, do you know why it is happening like this? any ideas already on how to improve. Of course, the best would be to combine both awesome examples from above, but I have a feeling that it might not be possible and this is why you added the
dev
flag. This is the only way I explain to myself why it is done now like this. Thoughts?I know I can explicitly add try-catch to my filter to get errors related to custom filters without a
dev
flag to also keep good errors for templates, but doing it with each filter seems cumbersome. Any opinions would be appreciated.