You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/09/24 20:00:56 UTC

git commit: [CB-4883]: Graceful handling of lazy loading errors.

Updated Branches:
  refs/heads/master bd2c667e9 -> cebd77692


[CB-4883]: Graceful handling of lazy loading errors.

Shows good error messages, and doesn't leave junk in the cache, on
failed lazy load downloads.


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/cebd7769
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/cebd7769
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/cebd7769

Branch: refs/heads/master
Commit: cebd776928b055d292b4133a24883f1e55c82bbb
Parents: bd2c667
Author: Braden Shepherdson <br...@gmail.com>
Authored: Tue Sep 24 13:47:59 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Tue Sep 24 13:59:35 2013 -0400

----------------------------------------------------------------------
 src/lazy_load.js | 14 +++++++++++++-
 src/platform.js  | 26 +++++++++++++-------------
 2 files changed, 26 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cebd7769/src/lazy_load.js
----------------------------------------------------------------------
diff --git a/src/lazy_load.js b/src/lazy_load.js
index 8e57c29..c3d7f52 100644
--- a/src/lazy_load.js
+++ b/src/lazy_load.js
@@ -23,6 +23,7 @@ var path          = require('path'),
     npm           = require('npm'),
     events        = require('./events'),
     request       = require('request'),
+    //http          = require('http'),
     config        = require('./config'),
     hooker        = require('./hooker'),
     https         = require('follow-redirects').https,
@@ -74,7 +75,18 @@ module.exports = {
                         request_options.proxy = proxy;
                     }
                     events.emit('log', 'Requesting ' + JSON.stringify(request_options) + '...');
-                    var req = request.get(request_options, function(err, req, body) { size = body.length; });
+                    var req = request.get(request_options, function(err, res, body) {
+                        if (err) {
+                            shell.rm('-rf', download_dir);
+                            d.reject(err);
+                        } else if (res.statusCode != 200) {
+                            shell.rm('-rf', download_dir);
+                            d.reject(new Error('HTTP error ' + res.statusCode + ' retrieving version ' + version + ' of ' + id + ' for ' + platform));
+                        } else {
+                            size = body.length;
+                        }
+                    });
+
                     req.pipe(zlib.createUnzip())
                     .pipe(tar.Extract({path:download_dir}))
                     .on('error', function(err) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cebd7769/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index e5c5319..24f16aa 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -69,19 +69,19 @@ module.exports = function platform(command, targets) {
 
             return hooks.fire('before_platform_add', opts)
             .then(function() {
-                var promises = targets.map(function(t) {
-                    return lazy_load.based_on_config(projectRoot, t)
-                    .then(function() {
-                        if (config_json.lib && config_json.lib[t]) {
-                            return call_into_create(t, projectRoot, cfg, config_json.lib[t].id, config_json.lib[t].version, config_json.lib[t].template);
-                        } else {
-                            return call_into_create(t, projectRoot, cfg, 'cordova', platforms[t].version, null);
-                        }
+                return targets.reduce(function(soFar, t) {
+                    return soFar.then(function() {
+                        return lazy_load.based_on_config(projectRoot, t)
+                        .then(function() {
+                            if (config_json.lib && config_json.lib[t]) {
+                                return call_into_create(t, projectRoot, cfg, config_json.lib[t].id, config_json.lib[t].version, config_json.lib[t].template);
+                            } else {
+                                return call_into_create(t, projectRoot, cfg, 'cordova', platforms[t].version, null);
+                            }
+                        }, function(err) {
+                            throw new Error('Unable to fetch platform ' + t + ': ' + err);
+                        });
                     });
-                });
-
-                return promises.reduce(function(soFar, f) {
-                    return soFar.then(f);
                 }, Q());
             })
             .then(function() {
@@ -225,7 +225,7 @@ function call_into_create(target, projectRoot, cfg, id, version, template_dir) {
 
     // Check if output directory already exists.
     if (fs.existsSync(output)) {
-        return Q.reject(err);
+        return Q.reject(new Error('Platform ' + target + ' already added'));
     } else {
         // Make sure we have minimum requirements to work with specified platform
         events.emit('log', 'Checking if platform "' + target + '" passes minimum requirements...');