From b2d7124424340b3c6534c0701bd10f9697be3433 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Tue, 11 Oct 2016 17:19:10 -0700 Subject: [PATCH] CB-11999 add message, catch exception if require fails --- bin/templates/cordova/Api.js | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js index bec578ce..28a0ab5e 100644 --- a/bin/templates/cordova/Api.js +++ b/bin/templates/cordova/Api.js @@ -109,13 +109,20 @@ function Api(platform, platformRootDir, events) { */ Api.createPlatform = function (destination, config, options, events) { events = setupEvents(events); - - return require('../../lib/create') - .create(destination, config, options, events) - .then(function (destination) { - var PlatformApi = require(path.resolve(destination, 'cordova/Api')); - return new PlatformApi(PLATFORM, destination, events); - }); + var result; + try { + result = require('../../lib/create') + .create(destination, config, options, events) + .then(function (destination) { + var PlatformApi = require(path.resolve(destination, 'cordova/Api')); + return new PlatformApi(PLATFORM, destination, events); + }); + } + catch (e) { + events.emit('error','createPlatform is not callable from the android project API.'); + throw(e); + } + return result; }; /** @@ -136,13 +143,20 @@ Api.createPlatform = function (destination, config, options, events) { */ Api.updatePlatform = function (destination, options, events) { events = setupEvents(events); - - return require('../../lib/create') - .update(destination, options, events) - .then(function (destination) { - var PlatformApi = require(path.resolve(destination, 'cordova/Api')); - return new PlatformApi('android', destination, events); - }); + var result; + try { + result = require('../../lib/create') + .update(destination, options, events) + .then(function (destination) { + var PlatformApi = require(path.resolve(destination, 'cordova/Api')); + return new PlatformApi('android', destination, events); + }); + } + catch (e) { + events.emit('error','updatePlatform is not callable from the android project API, you will need to do this manually.'); + throw(e); + } + return result; }; /**