Closed brokolja closed 6 years ago
The fix here isn't using the async
version, but rather that you're using an empty string when res
doesn't exist (which will result in an empty file). I think we should find out why env.renderString(file.contents.toString(), context)
returns undefined
sometimes instead.
In: https://github.com/mozilla/nunjucks/blob/master/src/environment.js at line: 501 you can see that nunjucks throws rendering errors if no callback is used with env.renderString. So we must use env.renderString with callback to catch errors within the callback if we can not change nunjucks sourcecode. Its not possible to catch an error which is thrown within another scope. But your right it seems that using the async nunjucks render function is not a good thing here because were dealing with streams. But even if it is not the best solution - my fix fixed the problem in my gulp-task.
If it throws we'll catch it since we're using it inside a try/catch
block.
Hi,
I fixed #22 by using the async version of renderString to catch/emit the error in the callback before its thrown. With this solution the gulp task will not stop on error - it will just show a message.
Greetings , Kolja Kutschera