From 9e3cdfda0241ad55720f7782c0d4bc9aeee54eaf Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 28 Jul 2017 16:50:42 -0700 Subject: [PATCH 1/2] Refactor error throwing from assertPageLoaded --- lighthouse-core/gather/gather-runner.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 6a8819cd2c5c..cd5e9f19d8bd 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -140,14 +140,23 @@ class GatherRunner { * @param {!Array} networkRecords */ static assertPageLoaded(url, driver, networkRecords) { + if (!driver.online) return; + const mainRecord = networkRecords.find(record => { // record.url is actual request url, so needs to be compared without any URL fragment. return URL.equalWithExcludedFragments(record.url, url); }); - if (driver.online && (!mainRecord || mainRecord.failed)) { - const message = mainRecord ? mainRecord.localizedFailDescription : 'timeout reached'; - log.error('GatherRunner', message); - const error = new Error(`Unable to load the page: ${message}`); + + let errorMessage; + if (!mainRecord) { + errorMessage = 'no document request found'; + } else if (mainRecord.failed) { + errorMessage = `failed document request (${mainRecord.localizedFailDescription})`; + } + + if (errorMessage) { + log.error('GatherRunner', errorMessage, url); + const error = new Error(`Unable to load page: ${errorMessage}`); error.code = 'PAGE_LOAD_ERROR'; throw error; } From fbaef640c6289b44cde813752fa0509d6ead0f3d Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 28 Jul 2017 16:57:40 -0700 Subject: [PATCH 2/2] test. --- lighthouse-core/test/gather/gather-runner-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-core/test/gather/gather-runner-test.js b/lighthouse-core/test/gather/gather-runner-test.js index 98737dbd097d..943fcf6967a4 100644 --- a/lighthouse-core/test/gather/gather-runner-test.js +++ b/lighthouse-core/test/gather/gather-runner-test.js @@ -647,7 +647,7 @@ describe('GatherRunner', function() { const records = []; assert.throws(() => { GatherRunner.assertPageLoaded(url, {online: true}, records); - }, /Unable.*timeout/); + }, /Unable.*no document request/); }); });