Fix error plumbing

master
Sven Slootweg 8 years ago
parent 05e291b08e
commit b31033381b

@ -4,13 +4,28 @@ var stream = require("stream");
var combiner = require("stream-combiner2");
var plumber = require("gulp-plumber");
var namedLog = require("gulp-named-log");
var util = require("util");
module.exports = function (name, streams) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var logger = namedLog(name, options.logger);
var streamList = [plumber(logger.error)].concat(streams).concat([logger.stream()]);
var streamList = streams.concat([logger.stream()]);
return combiner.obj(streamList);
/* We need to patch in the `pipe` handler manually, as this monkeypatch doesn't
* carry over to Duplex streams that are created by `stream-combiner2`. The
* `stream-combiner2` library will take care of re-emitting the errors on the
* combined stream, so we don't need `gulp-plumber` in our actual pipeline.
*/
var plumberStream = plumber(function (err) {
logger.error(err.toString());
/* Ensure that the task finishes, so as to not break `gulp.watch`. */
this.emit("end");
});
var combinedStream = combiner.obj(streamList);
plumberStream.pipe(combinedStream);
return combinedStream;
};

@ -4,15 +4,28 @@ const stream = require("stream");
const combiner = require("stream-combiner2");
const plumber = require("gulp-plumber");
const namedLog = require("gulp-named-log");
const util = require("util");
module.exports = function(name, streams, options = {}) {
let logger = namedLog(name, options.logger);
let streamList = [
plumber(logger.error)
].concat(streams).concat([
let streamList = streams.concat([
logger.stream()
]);
return combiner.obj(streamList)
/* We need to patch in the `pipe` handler manually, as this monkeypatch doesn't
* carry over to Duplex streams that are created by `stream-combiner2`. The
* `stream-combiner2` library will take care of re-emitting the errors on the
* combined stream, so we don't need `gulp-plumber` in our actual pipeline.
*/
let plumberStream = plumber(function(err) {
logger.error(err.toString());
/* Ensure that the task finishes, so as to not break `gulp.watch`. */
this.emit("end");
});
let combinedStream = combiner.obj(streamList);
plumberStream.pipe(combinedStream);
return combinedStream;
}
Loading…
Cancel
Save