generator: Improve error stack trace for errors in filters.
Reason/Context
When developing templates sometimes you make an implementation mistake in a filter could be a simple cannot call method of undefined
, however when that happens we receive no information about where in the filter the error occurred. It sometimes takes a lot of time to figure out where the error is really located, and sometimes the only approach is step by step console log and comment out functionality.
As an example with the html template if you add a check to the following line such as
obj.oneOf().length > 0 ||
it gives you the stack trace:
Something went wrong:
Template render error: (PATH@asyncapi\generator\node_modules\@asyncapi\html-template\template\index.html)
Template render error: (PATH@asyncapi\generator\node_modules\@asyncapi\html-template\partials\content.html)
Template render error: (PATH@asyncapi\generator\node_modules\@asyncapi\html-template\partials\operations.html)
TypeError: Cannot read property 'length' of null
at Object._prettifyError (PATH@asyncapi\generator\node_modules\nunjucks\src\lib.js:36:11)
at PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:561:19
at eval (eval at _compile (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:49:11)
at PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:569:11
at eval (eval at _compile (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:64:12)
at PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:569:11
at eval (eval at _compile (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:10:11)
at PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:611:9
at eval (eval at _compile (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:54:12)
at PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:611:9
at eval (eval at _compile (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:10:11)
at PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:611:9
at Template.root [as rootRenderFunc] (eval at _compile (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:75:3)
at Template.getExported (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:609:10)
at eval (eval at _compile (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:9:5)
at Environment.getTemplate (PATH@asyncapi\generator\node_modules\nunjucks\src\environment.js:277:9)
Which does not give you any information about where in the filter the error is located. This issue is based on the following Slack discussion: https://asyncapi.slack.com/archives/CQVJXFNQL/p1588245326200400
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (20 by maintainers)
Closing. Nunjucks render engine is not something we will invest in imho and the new React engine has everything that is needed already
@jonaslagoni debug merged in, you can add issues š
@jonaslagoni yeap, this is why Iām working on it at the moment š
So far found https://github.com/mozilla/nunjucks/issues/1137 and https://github.com/mozilla/nunjucks/issues/975
Iām able to throw proper errors only if I do it from inside the filter, and console.log out the errors
Then I get error:
Pretty much what we need, but yeah, you have to manually add it to a specific filter š¤