Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to configure gulp-postcss not to fail a build on css syntax error #51

Closed
11bit opened this issue Aug 21, 2015 · 11 comments
Closed

Comments

@11bit
Copy link

11bit commented Aug 21, 2015

Is there a way to configure PostCSS plugin to just log the error and not fail a build when it encounters a css syntax error? It may be useful in some live-reloading workflows. For instance when I use gulp with browser-sync's watch plugin that lints code on every change the failed build also fails watching process so I have to restart it every time.

As a possible solution gulp-poctcss may have a switch to handle all postcss errors, log them to console and proceed:

gulp.src(cssFile)
    .pipe(postcss([...], {failOnError: false}))
@matchabros
Copy link

This might be helpful for you - https://www.npmjs.com/package/gulp-plumber

@TrySound
Copy link
Member

@11bit @matchabros It's gulp issue. Where it catches only last pipe error. I decide it with

gulp.task('css', function (done) {
  return gulp.src(...)
    // not last pipe
    .pipe(postcss(...))
    .on('error', done)
    // Last pipe error will be caught
    .pipe(gulp.dest(...))
})

@11bit
Copy link
Author

11bit commented Aug 22, 2015

@matchabros @TrySound Thanks guys. Anyway gulp 4 is going to bring a new error handling. I hope it won't need to use plumber of custom error handling no more.

@lmartins
Copy link

I've tried using gulp-plumber for this unfortunately it still stops compilation on every single fail.

gulp.task('css', function () {
    var processors = [
        atImport,
        simplevars,
        map(opts),
        nestedcss,
        colorFunction,
        ms,
        lost,
        autoprefixer({browsers: ['last 1 version', 'ie 10']})
    ];
    return gulp.src('./css/main.css')
        .pipe( plumber() )
        .pipe( sourcemaps.init() )
        .pipe( postcss(processors) )
        .pipe( rucksack() )
        // .pipe( nano() )
        .pipe( sourcemaps.write('.') )
        .pipe( gulp.dest('build/css/') )
        .pipe( browserSync.stream({match: "**/*.css"}) );
        // .pipe( browserSync.reload({stream: true, match: "**/*.css"}) );
});

@TrySound
Copy link
Member

@lmartins plumber is ugly hack. You can see here in case how I organize my build process.

@lmartins
Copy link

Thanks @TrySound, will study your example :)

@matchabros
Copy link

@lmartins your issue might be coming from not using an error handler with gulp-plumber.

I just had a look myself and got rid of my errorHandler inside of .pipe(plumber()) and it does stop compiling on an error.

Here's the errorHandler I use in my build.

function errorAlert(err) {
  $.notify.onError({
    title: 'Gulp Error',
    message: 'An error occured, check your terminal',
    sound: 'Basso'
  })(err);
  gutil.log(gutil.colors.red(err.toString()));
  this.emit('end');
}

@TrySound
Copy link
Member

@matchabros The problem is that for CI this code won't exit with error code.

@matchabros
Copy link

@TrySound Pardon me if my lack of knowledge will come out right now, but could you elaborate on what you meant ?

@TrySound
Copy link
Member

@matchabros If you use something like travis ci,this.emit('end') will end task but without error. It will just passes by with some log.

@matchabros
Copy link

@TrySound I see, thanks for taking a moment and explaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants