From b2af31c72b5dd9504aa85390b1ab99bfc4a02e56 Mon Sep 17 00:00:00 2001 From: Michael Giambalvo Date: Wed, 31 Aug 2016 13:42:18 -0700 Subject: [PATCH 1/3] fix(launcher): Handle uncaught exceptions --- lib/exitCodes.ts | 2 +- lib/launcher.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/exitCodes.ts b/lib/exitCodes.ts index cb71e86d6..c7e230f38 100644 --- a/lib/exitCodes.ts +++ b/lib/exitCodes.ts @@ -85,7 +85,7 @@ export class ErrorHandler { if (errMsgs && errMsgs.length > 0) { for (let errPos in errMsgs) { let errMsg = errMsgs[errPos]; - if (e.message.indexOf(errMsg) !== -1) { + if (e.message && e.message.indexOf(errMsg) !== -1) { return true; } } diff --git a/lib/launcher.ts b/lib/launcher.ts index 634c4af16..115a321b9 100644 --- a/lib/launcher.ts +++ b/lib/launcher.ts @@ -179,7 +179,10 @@ let initFn = function(configFile: string, additionalConfig: Config) { // 4) Run tests. let scheduler = new TaskScheduler(config); - process.on('uncaughtException', (e: Error) => { + process.on('uncaughtException', (exc: (Error|string)) => { + // If the exception is a raw string, wrap it in an Error. + let e = (typeof exc == 'string') ? new Error(exc) : exc; + let errorCode = ErrorHandler.parseError(e); if (errorCode) { let protractorError = e as ProtractorError; @@ -188,6 +191,7 @@ let initFn = function(configFile: string, additionalConfig: Config) { protractorError.stack); process.exit(errorCode); } else { + logger.error(e); logger.error(e.message); logger.error(e.stack); process.exit(ProtractorError.CODE); From 48caed5d5dcb106b2961494b6e291f5aa8b42d29 Mon Sep 17 00:00:00 2001 From: Michael Giambalvo Date: Wed, 31 Aug 2016 14:28:57 -0700 Subject: [PATCH 2/3] Clean up instances where we're throwing strings instead of Errors. --- lib/browser.ts | 13 ++++++++----- lib/cli.ts | 2 +- lib/launcher.ts | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/browser.ts b/lib/browser.ts index 6383419d8..ab40a9727 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -448,8 +448,9 @@ export class ProtractorBrowser extends Webdriver { return runWaitForAngularScript() .then((browserErr: Function) => { if (browserErr) { - throw 'Error while waiting for Protractor to ' + - 'sync with the page: ' + JSON.stringify(browserErr); + throw new Error( + 'Error while waiting for Protractor to ' + + 'sync with the page: ' + JSON.stringify(browserErr)); } }) .then( @@ -790,7 +791,8 @@ export class ProtractorBrowser extends Webdriver { return angularVersion; }, (err: Error) => { - throw 'Error while running testForAngular: ' + err.message; + throw new Error( + 'Error while running testForAngular: ' + err.message); }) .then(loadMocks, deferred.reject); @@ -812,8 +814,9 @@ export class ProtractorBrowser extends Webdriver { .then( null, (err: Error) => { - throw 'Error while running module script ' + name + ': ' + - err.message; + throw new Error( + 'Error while running module script ' + name + ': ' + + err.message); }) .then(null, deferred.reject); } diff --git a/lib/cli.ts b/lib/cli.ts index 70074d92c..75c436ad1 100644 --- a/lib/cli.ts +++ b/lib/cli.ts @@ -72,7 +72,7 @@ optimist .string('capabilities.tunnel-identifier') .check(function(arg: any) { if (arg._.length > 1) { - throw 'Error: more than one config file specified'; + throw new Error('Error: more than one config file specified'); } }); diff --git a/lib/launcher.ts b/lib/launcher.ts index 115a321b9..77caec9d1 100644 --- a/lib/launcher.ts +++ b/lib/launcher.ts @@ -191,7 +191,6 @@ let initFn = function(configFile: string, additionalConfig: Config) { protractorError.stack); process.exit(errorCode); } else { - logger.error(e); logger.error(e.message); logger.error(e.stack); process.exit(ProtractorError.CODE); From 5fdc5e97392a1c073745659dbf11b5013440b749 Mon Sep 17 00:00:00 2001 From: Michael Giambalvo Date: Wed, 31 Aug 2016 14:56:31 -0700 Subject: [PATCH 3/3] Make the string wrapping clearer. --- lib/launcher.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/launcher.ts b/lib/launcher.ts index 77caec9d1..19bc5af96 100644 --- a/lib/launcher.ts +++ b/lib/launcher.ts @@ -180,8 +180,7 @@ let initFn = function(configFile: string, additionalConfig: Config) { let scheduler = new TaskScheduler(config); process.on('uncaughtException', (exc: (Error|string)) => { - // If the exception is a raw string, wrap it in an Error. - let e = (typeof exc == 'string') ? new Error(exc) : exc; + let e = (exc instanceof Error) ? exc : new Error(exc); let errorCode = ErrorHandler.parseError(e); if (errorCode) {