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(gather): define new DNS failure LH Error #6579

Merged
merged 7 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 13 additions & 2 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,19 @@ class GatherRunner {
if (!mainRecord) {
errorDef = LHError.errors.NO_DOCUMENT_REQUEST;
} else if (mainRecord.failed) {
errorDef = {...LHError.errors.FAILED_DOCUMENT_REQUEST};
errorDef.message += ` ${mainRecord.localizedFailDescription}.`;
const netErr = mainRecord.localizedFailDescription;
// Match all resolution and DNS failures
// https://cs.chromium.org/chromium/src/net/base/net_error_list.h?rcl=cd62979b
if (
netErr.startsWith('net::ERR_NAME_NOT_RESOLVED') ||
netErr.startsWith('net::ERR_NAME_RESOLUTION_FAILED') ||
Copy link
Member

Choose a reason for hiding this comment

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

just test equality for these two? Or are these expected as prefixes?

netErr.startsWith('net::ERR_DNS_')
) {
errorDef = {...LHError.errors.DNS_FAILURE};
Copy link
Member

Choose a reason for hiding this comment

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

if no string/message altering, no need to object spread to get a copy (e.g. see NO_DOCUMENT_REQUEST above)

} else {
Copy link
Member

Choose a reason for hiding this comment

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

these conditionals are multiplying in an unseemly fashion. Maybe #6457 can take on cleaning them up with early returns @exterkamp

errorDef = {...LHError.errors.FAILED_DOCUMENT_REQUEST};
errorDef.message += ` ${netErr}.`;
}
} else if (mainRecord.hasErrorStatusCode()) {
errorDef = {...LHError.errors.ERRORED_DOCUMENT_REQUEST};
errorDef.message += ` Status code: ${mainRecord.statusCode}.`;
Expand Down
7 changes: 7 additions & 0 deletions lighthouse-core/lib/lh-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ const ERRORS = {
lhrRuntimeError: true,
},

// DNS failure on main document (no resolution, broken DNS)
DNS_FAILURE: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

proto update :)

code: 'DNS_FAILURE',
message: strings.dnsFailure,
lhrRuntimeError: true,
},

// Hey! When adding a new error type, update lighthouse-result.proto too.
};

Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/lib/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ module.exports = {
requestContentTimeout: 'Fetching resource content has exceeded the allotted time',
urlInvalid: `The URL you have provided appears to be invalid.`,
protocolTimeout: `Waiting for DevTools protocol response has exceeded the allotted time.`,
dnsFailure: `DNS servers could not resolve the provided domain.`,
};
14 changes: 13 additions & 1 deletion lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,18 @@ describe('GatherRunner', function() {
assert.equal(error.code, 'ERRORED_DOCUMENT_REQUEST');
assert.ok(/^Lighthouse was unable to reliably load/.test(error.friendlyMessage));
});

it('fails when page domain doesn\'t resolve', () => {
const url = 'http://the-page.com';
const mainRecord = new NetworkRequest();
mainRecord.url = url;
mainRecord.failed = true;
mainRecord.localizedFailDescription = 'net::ERR_NAME_NOT_RESOLVED';
const error = GatherRunner.getPageLoadError(url, [mainRecord]);
assert.equal(error.message, 'DNS_FAILURE');
assert.equal(error.code, 'DNS_FAILURE');
assert.ok(/^DNS servers could not resolve/.test(error.friendlyMessage));
});
});

describe('#assertNoSecurityIssues', () => {
Expand Down Expand Up @@ -1059,7 +1071,7 @@ describe('GatherRunner', function() {
config: new Config({}),
}).then(artifacts => {
assert.equal(artifacts.LighthouseRunWarnings.length, 1);
assert.ok(/unable.*load the page/.test(artifacts.LighthouseRunWarnings[0]));
assert.ok(/DNS servers could not resolve/.test(artifacts.LighthouseRunWarnings[0]));
});
});

Expand Down
2 changes: 2 additions & 0 deletions proto/lighthouse-result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ enum LighthouseError {
PROTOCOL_TIMEOUT = 17;
// Used when the page is not responding after maxWaitForLoad.
PAGE_HUNG = 18;
// DNS timed out for the main 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.

handles more cases than just a timeout?

DNS_FAILURE = 19;
}

// The overarching Lighthouse Response object (LHR)
Expand Down