From ab3d349cf2ca92e72ed1d4a32fe9d523a740bb35 Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Thu, 11 Feb 2016 12:19:28 -0800 Subject: [PATCH] Only ignore dfu-util errors when 'File download successfully' is part of stdout Fixes #206 --- commands/UpdateCommand.js | 9 +-------- lib/dfu.js | 10 +++++++++- lib/utilities.js | 5 +++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/commands/UpdateCommand.js b/commands/UpdateCommand.js index 9c0873dd2..31ab26ac1 100644 --- a/commands/UpdateCommand.js +++ b/commands/UpdateCommand.js @@ -84,14 +84,7 @@ UpdateCommand.prototype = extend(BaseCommand.prototype, { steps.push(function (cb) { var binary = path.resolve(__dirname, '..', 'updates', updates[part]); whenNode.bindCallback( - dfu.write(binary, part, leave) - .then(null, function (err) { - // don't reject for get_status error - if (err.indexOf('Error during download get_status') >= 0) { - return ''; - } - }) - .delay(2000) + dfu.write(binary, part, leave).delay(2000) , cb); }); first = false; diff --git a/lib/dfu.js b/lib/dfu.js index 242192854..2f94f30c6 100644 --- a/lib/dfu.js +++ b/lib/dfu.js @@ -142,7 +142,15 @@ var that = module.exports = { } that.checkBinaryAlignment('-D ' + binaryPath); - return utilities.deferredSpawnProcess(cmd, args); + return utilities.deferredSpawnProcess(cmd, args).then(function(output) { + return when.resolve(output.stdout.join('\n')); + }).catch(function(output) { + // If this line is printed, it actually worked. Ignore other errors. + if (output.stdout.indexOf('File downloaded successfully') >= 0) { + return when.resolve(output.stdout.join('\n')); + } + return when.reject(output.stderr.join('\n')); + }); }, getCommand: function () { diff --git a/lib/utilities.js b/lib/utilities.js index 6a1071d98..81a30a1e7 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -111,10 +111,11 @@ var that = module.exports = { } child.on('close', function (code) { + var output = { stdout: stdout, stderr: errors }; if (!code) { - tmp.resolve(stdout.join('\n')); + tmp.resolve(output); } else { - tmp.reject(errors.join('\n')); + tmp.reject(output); } }); } catch (ex) {