Updated Branches: refs/heads/cordova-client 6c3f34260 -> 458f09c4f
added uncaughtException handler rather than abruptly calling process.exit Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/458f09c4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/458f09c4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/458f09c4 Branch: refs/heads/cordova-client Commit: 458f09c4fb4a965cfe41d83ba1baa09e1b8b219b Parents: 878a655 Author: Mike Reinstein <reinstein.m...@gmail.com> Authored: Tue Sep 25 15:01:35 2012 -0400 Committer: Fil Maj <maj....@gmail.com> Committed: Tue Sep 25 17:36:04 2012 -0700 ---------------------------------------------------------------------- bin/cordova | 6 ++++++ src/platform.js | 50 +++++++++++++++++++++++++------------------------- src/util.js | 12 +++--------- 3 files changed, 34 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/458f09c4/bin/cordova ---------------------------------------------------------------------- diff --git a/bin/cordova b/bin/cordova index 439ea35..a58a14d 100755 --- a/bin/cordova +++ b/bin/cordova @@ -3,6 +3,12 @@ var cordova = require('./../cordova') , cmd = process.argv[2] , opts = process.argv.slice(3, process.argv.length) +// provide clean output on exceptions rather than dumping a stack trace +process.on('uncaughtException', function(error){ + console.error(err); + process.exit(1); +}); + if (cmd === undefined) { console.log(cordova.help()); } else if (cordova.hasOwnProperty(cmd)) { http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/458f09c4/src/platform.js ---------------------------------------------------------------------- diff --git a/src/platform.js b/src/platform.js index e8586e5..db32dd1 100644 --- a/src/platform.js +++ b/src/platform.js @@ -24,7 +24,9 @@ module.exports = function platform(command, target, callback) { var platforms = cfg.ls_platforms(); if (platforms.length) { return platforms.join('\n'); - } else return 'No platforms added. Use `cordova platform add <platform>`.'; + } else { + return 'No platforms added. Use `cordova platform add <platform>`.'; + } break; case 'add': var output = path.join(projectRoot, 'platforms', target); @@ -38,30 +40,28 @@ module.exports = function platform(command, target, callback) { // TODO: eventually refactor to allow multiple versions to be created. // Check if output directory already exists. if (fs.existsSync(output)) { - throw 'Platform "' + target + '" already exists' - } else { - // directory doesn't exist, run platform's create script - var bin = path.join(__dirname, '..', 'lib', target, 'bin', 'create'); - var pkg = cfg.packageName().replace(/[^\w.]/g,'_'); - var name = cfg.name().replace(/\W/g,'_'); - var command = util.format('"%s" "%s" "%s" "%s"', bin, output, pkg, name); - var create = shell.exec(command, {silent:true}); - if (create.code > 0) { - throw ('An error occured during creation of ' + target + ' sub-project. ' + create.output); - } else { - cfg.add_platform(target); - switch(target) { - case 'android': - var android = new android_parser(output); - android.update_from_config(cfg); - if (callback) callback(); - break; - case 'ios': - var ios = new ios_parser(output); - ios.update_from_config(cfg, callback); - break; - } - } + throw new Error('Platform "' + target + '" already exists' ); + } + // directory doesn't exist, run platform's create script + var bin = path.join(__dirname, '..', 'lib', target, 'bin', 'create'); + var pkg = cfg.packageName().replace(/[^\w.]/g,'_'); + var name = cfg.name().replace(/\W/g,'_'); + var command = util.format('"%s" "%s" "%s" "%s"', bin, output, pkg, name); + var create = shell.exec(command, {silent:true}); + if (create.code > 0) { + throw new Error('An error occured during creation of ' + target + ' sub-project. ' + create.output); + } + cfg.add_platform(target); + switch(target) { + case 'android': + var android = new android_parser(output); + android.update_from_config(cfg); + if (callback) callback(); + break; + case 'ios': + var ios = new ios_parser(output); + ios.update_from_config(cfg, callback); + break; } break; case 'remove': http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/458f09c4/src/util.js ---------------------------------------------------------------------- diff --git a/src/util.js b/src/util.js index f56eb24..f37c04c 100644 --- a/src/util.js +++ b/src/util.js @@ -37,20 +37,14 @@ module.exports = { * @throws Javascript Error on failure */ getPlatformLib: function getPlatformLib(target) { - // TODO: process.exit(1) is a pretty terrible pattern because it kills - // excecution immediately and prevents cleanup routines. However, - // I don't want to just spew a stack trace to the user either. - // verify platform is supported if (!repos[target]) { - console.error('platform "' + target + '" not found.'); - process.exit(1); + throw new Error('platform "' + target + '" not found.'); } - // verify that git command line is available + // verify git command line is available if (!shell.which('git')) { - console.error('"git" command not found.'); - process.exit(1); + throw new Error('"git" command not found.'); } // specify which project tag to check out. minimum tag is 2.1.0rc1