From 9498b1057b5ac1fd9ebde8274e16b3859a0f03cc Mon Sep 17 00:00:00 2001 From: Georgii Dolzhykov Date: Thu, 14 Jun 2018 20:23:13 +0300 Subject: [PATCH] fix(helpers): support thrown strings and numbers in getExceptionMessage (#2715) Of course, strings aren't proper errors, but scripts sometimes do that, and Puppeteer loses such error messages. --- lib/helper.js | 2 +- test/page.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/helper.js b/lib/helper.js index 89e4c266..57bdc664 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -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) { diff --git a/test/page.spec.js b/test/page.spec.js index c549d1f1..4d18336c 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -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);