carlitoplatanito / gulp-nunjucks-render

[Gulp](https://github.com/wearefractal/gulp) plugin to render [Nunjucks](http://mozilla.github.io/nunjucks/) templates
149 stars 33 forks source link

How to handle error? #70

Closed spinxdigital closed 5 years ago

spinxdigital commented 5 years ago

Here is my code.

gulp.task('nunjucks', function () {
  return gulp.src('html/pages/**/*.+(html|nunjucks)')
    .pipe($.nunjucksRender({
      path: ['html/templates']
    }))
    .pipe(gulp.dest('dist'));
});
kevinmpowell commented 5 years ago

@spinxdigital can you provide more details about the error you're seeing? There's not enough context in this comment.

spinxdigital commented 5 years ago

Actually on each error on template compiling I was getting error and I had restart gulp watch. But now I can handle error by below code (with plumber).

gulp.task('nunjucks', function () {

  return gulp.src('app/pages/**/*.+(html|nunjucks)')
    .pipe($.data(readTemplateData()))
    .pipe($.plumber({
      errorHandler: onError
    }))
    .pipe($.nunjucksRender({
      path: ['app/templates']
    }))
    .pipe(gulp.dest('dist'));
});