Make helper.getExceptionMessage synchronous

We now have description of an exception, no need for a roundtrip
to the backend.
This commit is contained in:
Andrey Lushnikov 2017-07-21 11:57:25 -07:00
parent 0960dc38d1
commit aba61de905
4 changed files with 11 additions and 26 deletions

View File

@ -165,10 +165,8 @@ class FrameManager extends EventEmitter {
}
expression = `Promise.resolve(${expression})`;
let { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.evaluate', { expression, contextId, returnByValue: false, awaitPromise: true });
if (exceptionDetails) {
let message = await helper.getExceptionMessage(this._client, exceptionDetails);
throw new Error('Evaluation failed: ' + message);
}
if (exceptionDetails)
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
return await helper.serializeRemoteObject(this._client, remoteObject);
}
@ -190,10 +188,8 @@ class FrameManager extends EventEmitter {
awaitPromise: true,
returnByValue: false,
});
if (exceptionDetails) {
let message = await helper.getExceptionMessage(this._client, exceptionDetails);
throw new Error('Evaluation failed: ' + message);
}
if (exceptionDetails)
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
/**
* @param {string} selector

View File

@ -207,8 +207,8 @@ class Page extends EventEmitter {
/**
* @param {!Object} exceptionDetails
*/
async _handleException(exceptionDetails) {
let message = await helper.getExceptionMessage(this._client, exceptionDetails);
_handleException(exceptionDetails) {
let message = helper.getExceptionMessage(exceptionDetails);
this.emit(Page.Events.PageError, new Error(message));
}

View File

@ -25,24 +25,13 @@ class Helper {
}
/**
* @param {!Connection} client
* @param {!Object} exceptionDetails
* @return {string}
*/
static async getExceptionMessage(client, exceptionDetails) {
let message = '';
let exception = exceptionDetails.exception;
if (exception) {
let response = await client.send('Runtime.callFunctionOn', {
objectId: exception.objectId,
functionDeclaration: 'function() { return this.message; }',
returnByValue: true,
});
message = response.result.value;
} else {
message = exceptionDetails.text;
}
static getExceptionMessage(exceptionDetails) {
if (exceptionDetails.exception)
return exceptionDetails.exception.description;
let message = exceptionDetails.text;
if (exceptionDetails.stackTrace) {
for (let callframe of exceptionDetails.stackTrace.callFrames) {
let location = callframe.url + ':' + callframe.lineNumber + ':' + callframe.columnNumber;

View File

@ -240,7 +240,7 @@ describe('Puppeteer', function() {
await page.waitFor('*');
fail('Failed waitFor did not throw.');
} catch (e) {
expect(e.message).toContain('Evaluation failed: document.querySelector is not a function');
expect(e.message).toContain('document.querySelector is not a function');
}
}));
it('should throw when frame is detached', SX(async function() {