Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: smooth rough edges of pageLoadError display and reporting #6083

Merged
merged 2 commits into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,19 @@ class GatherRunner {
return URL.equalWithExcludedFragments(record.url, url);
});

let errorCode;
let errorReason;
let errorDef;
if (!mainRecord) {
errorCode = LHError.errors.NO_DOCUMENT_REQUEST;
errorDef = LHError.errors.NO_DOCUMENT_REQUEST;
} else if (mainRecord.failed) {
errorCode = LHError.errors.FAILED_DOCUMENT_REQUEST;
errorReason = mainRecord.localizedFailDescription;
errorDef = {...LHError.errors.FAILED_DOCUMENT_REQUEST};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so fancy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so fancy?

easier than Object.assign()? Dunno :) Just needed a shallow copy so it's not modifying the original message

errorDef.message += ` ${mainRecord.localizedFailDescription}.`;
} else if (mainRecord.hasErrorStatusCode()) {
errorCode = LHError.errors.ERRORED_DOCUMENT_REQUEST;
errorReason = `Status code: ${mainRecord.statusCode}`;
errorDef = {...LHError.errors.ERRORED_DOCUMENT_REQUEST};
errorDef.message += ` Status code: ${mainRecord.statusCode}.`;
}

if (errorCode) {
const error = new LHError(errorCode, {reason: errorReason});
log.error('GatherRunner', error.message, url);
return error;
if (errorDef) {
return new LHError(errorDef);
}
}

Expand Down Expand Up @@ -279,9 +276,8 @@ class GatherRunner {
if (!driver.online) pageLoadError = undefined;

if (pageLoadError) {
passContext.LighthouseRunWarnings.push('Lighthouse was unable to reliably load the ' +
'page you requested. Make sure you are testing the correct URL and that the server is ' +
'properly responding to all requests.');
log.error('GatherRunner', pageLoadError.message, passContext.url);
passContext.LighthouseRunWarnings.push(pageLoadError.friendlyMessage);
}

// Expose devtoolsLog, networkRecords, and trace (if present) to gatherers
Expand Down Expand Up @@ -333,7 +329,6 @@ class GatherRunner {
/** @type {Partial<LH.GathererArtifacts>} */
const gathererArtifacts = {};

const pageLoadFailures = [];
const resultsEntries = /** @type {GathererResultsEntries} */ (Object.entries(gathererResults));
for (const [gathererName, phaseResultsPromises] of resultsEntries) {
if (gathererArtifacts[gathererName] !== undefined) continue;
Expand All @@ -349,18 +344,11 @@ class GatherRunner {
// An error result must be non-fatal to not have caused an exit by now,
// so return it to runner to handle turning it into an error audit.
gathererArtifacts[gathererName] = err;
// Track page load errors separately, so we can fail loudly if needed.
if (LHError.isPageLoadError(err)) pageLoadFailures.push(err);
}

if (gathererArtifacts[gathererName] === undefined) {
throw new Error(`${gathererName} failed to provide an artifact.`);
}

// Fail the run if more than 50% of all artifacts failed due to page load failure.
if (pageLoadFailures.length > Object.keys(gathererArtifacts).length * 0.5) {
throw LHError.fromLighthouseError(pageLoadFailures[0]);
}
}

// Take only unique LighthouseRunWarnings.
Expand Down
9 changes: 0 additions & 9 deletions lighthouse-core/lib/lh-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ class LighthouseError extends Error {
Error.captureStackTrace(this, LighthouseError);
}

/**
* @param {{code?: string}} err
* @return {err is LighthouseError}
*/
static isPageLoadError(err) {
return err.code === ERRORS.NO_DOCUMENT_REQUEST.code ||
err.code === ERRORS.FAILED_DOCUMENT_REQUEST.code;
}

/**
* @param {LighthouseError} err
* @return {LighthouseError}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
didntCollectScreenshots: `Chrome didn't collect any screenshots during the page load. Please make sure there is content visible on the page, and then try re-running Lighthouse.`,
badTraceRecording: `Something went wrong with recording the trace over your page load. Please run Lighthouse again.`,
pageLoadTookTooLong: `Your page took too long to load. Please follow the opportunities in the report to reduce your page load time, and then try re-running Lighthouse.`,
pageLoadFailed: `Your page failed to load. Verify that the URL is valid and re-run Lighthouse.`,
pageLoadFailed: `Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests.`,
internalChromeError: `An internal Chrome error occurred. Please restart Chrome and try re-running Lighthouse.`,
requestContentTimeout: 'Fetching resource content has exceeded the allotted time',
urlInvalid: `The URL you have provided appears to be invalid.`,
Expand Down
4 changes: 1 addition & 3 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ class Runner {
static getArtifactRuntimeError(artifacts) {
for (const possibleErrorArtifact of Object.values(artifacts)) {
if (possibleErrorArtifact instanceof LHError && possibleErrorArtifact.lhrRuntimeError) {
const errorMessage = possibleErrorArtifact.friendlyMessage ?
`${possibleErrorArtifact.friendlyMessage} (${possibleErrorArtifact.message})` :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this concatenation is now directly handled by gather runner now, right? was that the only case we fell into this path?

Copy link
Member Author

@brendankenny brendankenny Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in gather runner. And since this was only introduced in #6051, there's nothing depending on it (only lr uses it, and only for human debugging; it's never shown to users).

message here is the error code, so it seemed redundant to keep it when the code is sitting right next to it on the object. I can add it back if we want to match the other place(s?) we put together an error string out of an lherror

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, sounds good as-is 👍

possibleErrorArtifact.message;
const errorMessage = possibleErrorArtifact.friendlyMessage || possibleErrorArtifact.message;

return {
code: possibleErrorArtifact.code,
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,15 @@ describe('GatherRunner', function() {
mainRecord.localizedFailDescription = 'foobar';
const error = GatherRunner.getPageLoadError(url, [mainRecord]);
assert.equal(error.message, 'FAILED_DOCUMENT_REQUEST');
assert.ok(/Your page failed to load/.test(error.friendlyMessage));
assert.ok(/^Lighthouse was unable to reliably load/.test(error.friendlyMessage));
});

it('fails when page times out', () => {
const url = 'http://the-page.com';
const records = [];
const error = GatherRunner.getPageLoadError(url, records);
assert.equal(error.message, 'NO_DOCUMENT_REQUEST');
assert.ok(/Your page failed to load/.test(error.friendlyMessage));
assert.ok(/^Lighthouse was unable to reliably load/.test(error.friendlyMessage));
});

it('fails when page returns with a 404', () => {
Expand All @@ -645,7 +645,7 @@ describe('GatherRunner', function() {
mainRecord.statusCode = 404;
const error = GatherRunner.getPageLoadError(url, [mainRecord]);
assert.equal(error.message, 'ERRORED_DOCUMENT_REQUEST');
assert.ok(/Your page failed to load/.test(error.friendlyMessage));
assert.ok(/^Lighthouse was unable to reliably load/.test(error.friendlyMessage));
});

it('fails when page returns with a 500', () => {
Expand All @@ -655,7 +655,7 @@ describe('GatherRunner', function() {
mainRecord.statusCode = 500;
const error = GatherRunner.getPageLoadError(url, [mainRecord]);
assert.equal(error.message, 'ERRORED_DOCUMENT_REQUEST');
assert.ok(/Your page failed to load/.test(error.friendlyMessage));
assert.ok(/^Lighthouse was unable to reliably load/.test(error.friendlyMessage));
});
});

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ describe('Runner', () => {
assert.ok(lhr.audits['test-audit'].errorMessage.includes(NO_FCP.code));
// And it bubbled up to the runtimeError.
assert.strictEqual(lhr.runtimeError.code, NO_FCP.code);
assert.ok(lhr.runtimeError.message.includes(NO_FCP.code));
assert.ok(lhr.runtimeError.message.includes(NO_FCP.message));
});

it('can handle array of outputs', async () => {
Expand Down