0

Our Gulp build process fails for some new developers like this:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: EMFILE, open '[some filename]'
    at Error (native)

The solution is to run:

ulimit -n 2048

So I'd like to catch the EMFILE error and replace it with a friendlier message. However, even wrapping the entire gulpfile.js in a try/catch doesn't seem to contain it.

1 Answer 1

1

It turns out that wrapping try/catch around everything doesn't work because the errors happen after (all) the code is executed. Injecting an error handler into every single pipe works:

function onError(e) {
    if (e.code === 'EMFILE') {
        console.error('Too many open files. You should run this command:\n    ulimit -n 2048');
        process.exit(1);
    }
    gutil.log(e.message);
    process.exit(1);
}

...
var result = bundler.bundle();

result = result
    .on('error', onError)
    .pipe(source(name))
    .pipe(buffer());
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.