Skip to content

Commit

Permalink
Refactor error throwing from assertPageLoaded (#2785)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored Jul 29, 2017
1 parent 4b9cbb5 commit 07817f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,23 @@ class GatherRunner {
* @param {!Array<WebInspector.NetworkRequest>} 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;
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ describe('GatherRunner', function() {
const records = [];
assert.throws(() => {
GatherRunner.assertPageLoaded(url, {online: true}, records);
}, /Unable.*timeout/);
}, /Unable.*no document request/);
});
});

Expand Down

0 comments on commit 07817f9

Please sign in to comment.