From 4c921ffe911068cc405fe46ebfbc2471a96940e9 Mon Sep 17 00:00:00 2001 From: michuNEEO Date: Fri, 26 Oct 2018 17:40:20 +0200 Subject: [PATCH] handle stream errors --- lib/docker.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/docker.js b/lib/docker.js index 4aae877..5337960 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -301,7 +301,26 @@ Docker.prototype.buildImage = function(file, opts, callback) { pack = tar.pack(file.context, { entries: file.src }); - return build(pack.pipe(zlib.createGzip())); + + if (callback === undefined) { + return new self.modem.Promise(function(resolve, reject) { + pack.on('error', function(error) { + return reject(error); + }); + pack.on('end', function() { + return resolve(build(stream)); + }); + var stream = pack.pipe(zlib.createGzip()); + }); + } else { + pack.on('error', function(error) { + return callback(error); + }); + pack.on('end', function() { + return build(stream); + }); + var stream = pack.pipe(zlib.createGzip()); + } } else { return build(file); }