From ed13cf7c22549d2b9286cbc3f10dab56bbd72f59 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Mon, 18 Dec 2023 20:22:18 -0800 Subject: [PATCH] Show error message if reading stream fails --- lib/command.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/command.js b/lib/command.js index 46930cd..22aa7e3 100644 --- a/lib/command.js +++ b/lib/command.js @@ -161,7 +161,18 @@ module.exports = function (proto) { return this.stream(format, function (err, stdout) { if (err) return callback(err); - streamToUnemptyBuffer(stdout, callback); + streamToUnemptyBuffer(stdout, (err, buffer) => { + if (err) { + // if we have an error, we want to include stderr + const stdErrOutput = Buffer.from(stderr.read()).toString('utf8') + if (stdErrOutput) { + err.message += `\n${stdErrOutput}` + } + return callback(err); + } + + callback(null, buffer); + }) }) }