Closed brandon-pereira closed 5 years ago
Hey, I can't seem to get error handling to work. I spent about half an hour trying to play around with the source, it seems that it should be changed to something like
try { const content = env.renderString(file.contents.toString()); console.log(content); if(content) { file.contents = new Buffer(content, context); } else { throw new Error("Invalid file"); }; this.push(file); } catch (err) {
because env.renderString returns 'null' if an error occurs. In your code when you go to add that "buffer" to the file.contents it errors.
I'm also not sure how to catch and handle errors on my end. I have this:
.pipe(nunjucks.compile({ path: ['./src/html', './src'], })).on('error', function(err) { console.log('\x1b[31m', 'nunjucksRender error: ', err.message, '\x1b[0m'); this.emit('end'); })
I also tried making the .on('error') portion attach to the nunjucks.compile function rather than the pipe and still had no success.
Any help appreciated!
The error handling is the same as all Gulp plugins, for better and for worse.
Hey, I can't seem to get error handling to work. I spent about half an hour trying to play around with the source, it seems that it should be changed to something like
because env.renderString returns 'null' if an error occurs. In your code when you go to add that "buffer" to the file.contents it errors.
I'm also not sure how to catch and handle errors on my end. I have this:
I also tried making the .on('error') portion attach to the nunjucks.compile function rather than the pipe and still had no success.
Any help appreciated!