make sure fatal errors get passed to client descriptively

Fix #284
This commit is contained in:
Jonathan Lipps
2013-04-08 17:36:54 -07:00
parent 96435a0eed
commit acc2b6bc8a
5 changed files with 42 additions and 5 deletions

View File

@@ -69,9 +69,22 @@ Android.prototype.start = function(cb, onDie) {
var didLaunch = false;
var onLaunch = _.bind(function(err) {
var skipRelaunchOn = [
'App never showed up'
, 'Could not sign one or more apks'
];
var checkShouldSkipRelaunch = function(msg) {
var skip = false;
_.each(skipRelaunchOn, function(skipMsg) {
skip = skip || msg.indexOf(skipMsg) !== -1;
});
return skip;
};
if (err) {
// This message is from adb.js. Must update when adb.js changes.
if (err.message === null || typeof err.message === 'undefined' || err.message.indexOf('App never showed up') === -1) {
if (err.message === null ||
typeof err.message === 'undefined' ||
!checkShouldSkipRelaunch(err.message.toString())) {
logger.error("Relaunching adb....");
var me = this;
this.adb.waitForDevice(function(){ didLaunch = true; me.push(null, true); cb(null); });

View File

@@ -13,7 +13,7 @@ function getResponseHandler(req, res) {
if (typeof response === "undefined" || response === null) {
response = {};
}
if (err !== null && typeof err.status !== 'undefined' && typeof err.value !== 'undefined') {
if (err !== null && typeof err !== "undefined" && typeof err.status !== 'undefined' && typeof err.value !== 'undefined') {
throw new Error("Looks like you passed in a response object as the " +
"first param to getResponseHandler. Err is always the " +
"first param! Fix your codes!");
@@ -75,6 +75,11 @@ var respondError = function(req, res, statusObj, value) {
}
if (typeof newValue === "object") {
if (_.has(value, "message")) {
// make sure this doesn't get obliterated
value.origValue = value.message;
message += " (Original error: " + value.message + ")";
}
newValue = _.extend({message: message}, value);
} else {
newValue = {message: message, origValue: value};

View File

@@ -3,10 +3,13 @@
var path = require('path')
, appPath = path.resolve(__dirname, "../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk")
, badAppPath = path.resolve(__dirname, "../../../sample-code/apps/ApiDemos/bin/ApiDemos-debugz.apk")
, appPkg = "com.example.android.apis"
, appAct = "ApiDemos"
, describeWd = require("../../helpers/driverblock.js").describeForApp(appPath,
"android", appPkg, appAct)
, driverBlock = require("../../helpers/driverblock.js")
, describeWd = driverBlock.describeForApp(appPath, "android", appPkg, appAct)
, describeBad = driverBlock.describeForApp(badAppPath, "android", appPkg,
appAct)
, should = require('should');
describeWd('basic', function(h) {
@@ -45,3 +48,12 @@ describeWd('basic', function(h) {
});
});
});
describeBad('bad app path', function(h) {
it('should throw an error', function(done) {
should.exist(h.connError);
var err = JSON.parse(h.connError.data);
err.value.origValue.should.include("Could not sign one or more apks");
done();
});
}, null, null, null, {expectConnError: true});

View File

@@ -30,10 +30,15 @@ var driverBlock = function(tests, host, port, caps, extraCaps) {
caps = (typeof caps === "undefined" || caps === null) ? _.clone(defaultCaps) : caps;
caps = _.extend(caps, typeof extraCaps === "undefined" ? {} : extraCaps);
var driverHolder = {driver: null, sessionId: null};
var expectConnError = extraCaps.expectConnError;
beforeEach(function(done) {
driverHolder.driver = wd.remote(host, port);
driverHolder.driver.init(caps, function(err, sessionId) {
if (expectConnError && err) {
driverHolder.connError = err;
return done();
}
should.not.exist(err);
driverHolder.sessionId = sessionId;
driverHolder.driver.setImplicitWaitTimeout(5000, function(err) {

View File

@@ -324,7 +324,9 @@ ADB.prototype.start = function(onReady, onExit) {
},
function(cb) {
if (!me.appPackage) return onReady("appPackage must be set.");
me.checkFastReset(function(err) { if (err) return onReady(err); cb(null); });
me.checkFastReset(function(err) {
if (err) return onReady(err); cb(null);
});
},
function(cb) {
me.installApp(function(err) { if (err) return onReady(err); cb(null); });