From e9834fedf1ac619c54cdc3b7be3f0a44a62d1e48 Mon Sep 17 00:00:00 2001 From: Hamar Date: Thu, 26 Jul 2018 14:51:17 +0200 Subject: [PATCH] Listen to stderr in toBuffer, so if the convert command fials we can return the error, instead of Error: Stream yields empty buffer --- lib/command.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/command.js b/lib/command.js index 2ff464fe..0a2aea9f 100644 --- a/lib/command.js +++ b/lib/command.js @@ -36,7 +36,7 @@ module.exports = function (proto) { } } - function streamToUnemptyBuffer(stream, callback) { + function streamToUnemptyBuffer(stream, callback, errorstream) { var done = false var buffers = [] @@ -44,6 +44,17 @@ module.exports = function (proto) { buffers.push(data) }) + if (errorstream) { + errorstream.on('data', function (error) { + if (error) { + debug('Error stream data: ' + error.toString()); + done = true; + buffers = null; + callback(error.toString()); + } + }); + } + stream.on('end', function () { var result, err; if (done) @@ -159,10 +170,10 @@ module.exports = function (proto) { throw new Error('gm().toBuffer() expects a callback.'); } - return this.stream(format, function (err, stdout) { + return this.stream(format, function (err, stdout, stderr) { if (err) return callback(err); - streamToUnemptyBuffer(stdout, callback); + streamToUnemptyBuffer(stdout, callback, stderr); }) }