Node-sass: Support success and error handling on renderSync

Created on 24 Oct 2014  路  1Comment  路  Source: sass/node-sass

I'm putting together a build task for a project using node-sass. I'm creating a watcher which recompiles sass when files change, using gulp.watch

The problem I'm encountering is that when I use renderSync, the watcher crashes if it encounters any build problems - the sass compile errors dump out and the watcher terminates.

If I use render, I'm able to catch build errors and provide helpful output, but of course now I'm not sure how to execute some logic at the end of the build. I want to be able to gracefully handle compile failures, but still execute the whole process synchronously.

Is this possible? I can imagine reasons it wouldn't be, but I'd like to hear from a contributor. What's my plan of attack?

>All comments

var sass = require('node-sass');
var css;

try {
  css = sass.renderSync();
  console.log('success');
} catch (err) {
  console.log('failure');
}
Was this page helpful?
0 / 5 - 0 ratings