Skip to content

Commit

Permalink
fix(helpers): support thrown strings and numbers in getExceptionMessa…
Browse files Browse the repository at this point in the history
…ge (#2715)

Of course, strings aren't proper errors, but scripts sometimes do that, and Puppeteer loses such error messages.
  • Loading branch information
thorn0 authored and aslushnikov committed Jun 14, 2018
1 parent 93e1289 commit 9498b10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Helper {
*/
static getExceptionMessage(exceptionDetails) {
if (exceptionDetails.exception)
return exceptionDetails.exception.description;
return exceptionDetails.exception.description || exceptionDetails.exception.value;
let message = exceptionDetails.text;
if (exceptionDetails.stackTrace) {
for (const callframe of exceptionDetails.stackTrace.callFrames) {
Expand Down
12 changes: 12 additions & 0 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ module.exports.addTests = function({testRunner, expect, puppeteer, DeviceDescrip
expect(error).toBeTruthy();
expect(error.message).toContain('not is not defined');
});
it('should support thrown strings as error messages', async({page, server}) => {
let error = null;
await page.evaluate(() => { throw 'qwerty'; }).catch(e => error = e);
expect(error).toBeTruthy();
expect(error.message).toContain('qwerty');
});
it('should support thrown numbers as error messages', async({page, server}) => {
let error = null;
await page.evaluate(() => { throw 100500; }).catch(e => error = e);
expect(error).toBeTruthy();
expect(error.message).toContain('100500');
});
it('should return complex objects', async({page, server}) => {
const object = {foo: 'bar!'};
const result = await page.evaluate(a => a, object);
Expand Down

0 comments on commit 9498b10

Please sign in to comment.