From ee038f945844490e7e57c78a57ee2a049d5a823d Mon Sep 17 00:00:00 2001 From: Sammy Jelin Date: Tue, 19 Jul 2016 14:58:38 -0700 Subject: [PATCH] fix(error message): do not crash of thrown error has made `stack` readonly (#3372) --- lib/element.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/element.ts b/lib/element.ts index f3f4807d4..2d3cd2fb7 100644 --- a/lib/element.ts +++ b/lib/element.ts @@ -429,16 +429,23 @@ export class ElementArrayFinder extends WebdriverWebElement { */ applyAction_(actionFn: Function): ElementArrayFinder { let callerError = new Error(); - let actionResults = this.getWebElements() - .then((arr: any) => { - return webdriver.promise.all(arr.map(actionFn)); - }) - .then(null, (e: Error) => { - let noSuchErr = (e as any); - noSuchErr.stack = - noSuchErr.stack + (callerError as any).stack; - throw noSuchErr; - }); + let actionResults = + this.getWebElements() + .then((arr: any) => { + return webdriver.promise.all(arr.map(actionFn)); + }) + .then(null, (e: Error) => { + let noSuchErr: any; + let stack: string; + if (e instanceof Error) { + noSuchErr = (e as any) + noSuchErr.stack = noSuchErr.stack + (callerError as any).stack; + } else { + noSuchErr = (new Error(e.toString()) as any); + noSuchErr.stack = (callerError as any).stack; + } + throw noSuchErr; + }); return new ElementArrayFinder( this.browser_, this.getWebElements, this.locator_, actionResults); }