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: create flag to prevent fatal error on bad status code #15494

Merged
merged 13 commits into from
Oct 20, 2023
Merged

Conversation

adrianaixba
Copy link
Collaborator

@adrianaixba adrianaixba commented Sep 26, 2023

@brendankenny
Copy link
Member

It should definitely be possible to test 404 pages, but otoh 404 is definitely an error state. You won't get CrUX data for URLs served with a 404 status, for instance. I personally favor the flag solution from #10493, but I also don't know the balance between folks wanting to test 404 pages explicitly vs other folks inadvertently testing the wrong page or a broken page without noticing (#10493 (comment), #10493 (comment), etc) to inform what the default behavior should be. So I don't have a strong opinion on warning vs error with flag to disable for 404s.

It does seem like a breaking change, though? e.g. I'm going to have to change my BigQuery queries to weed out 404 pages based on the warning after this. People running this in CI (or the suggestion that LHCI should handle the check) will have to go make that change as well.

@adrianaixba
Copy link
Collaborator Author

@brendankenny

So I don't have a strong opinion on warning vs error with flag to disable for 404s.

It seemed that the consensus was to do a warning instead of the flag, though I also don't have a strong opinion.

You won't get CrUX data for URLs served with a 404 status, for instance

This is a good point. Can't think of one on the spot but is there currently another instance where we would get a Lighthouse result, but not CrUX data? My thinking here is that if we do this already, it won't be so bad here?

Maybe some more discussion is needed on #10493?

@brendankenny
Copy link
Member

I don't want to re-litigate if there was consensus, but if this is going to happen, it would definitely be ideal if it were rolled into a major release.

@benschwarz
Copy link
Contributor

IMO there should be a command line switch to invoke error page testing.

If an error is encountered when the switch is not present, the error message should highlight that the page errored and to try again, or that you can intentionally ignore the error HTTP status to test the page.

@connorjclark
Copy link
Collaborator

connorjclark commented Oct 2, 2023

How about a flag --fatal-on-404 (or whatever) to keep current behavior that is off by default, but in HTTP Archive we enable it (and document that anyone doing bulk audits may wish to do the same)?

Or: keep current behavior, but have a flag for --ignore-status-code (which we would enable for DevTools by default, and maybe recommend the flag in a warning when not included and we see a 404)

@adrianaixba adrianaixba changed the title core: warn for a page that returns with a 404 core: create flag to warn for a page that returns a 404 Oct 9, 2023
@@ -46,6 +54,8 @@ function getNetworkError(mainRecord) {
return new LighthouseError(
LighthouseError.errors.FAILED_DOCUMENT_REQUEST, {errorDetails: netErr});
}
} else if (mainRecord.statusCode === 404 && context.ignoreStatusCode) {
context.warnings.push(str_(UIStrings.warning404));
} else if (mainRecord.hasErrorStatusCode()) {
Copy link
Member

Choose a reason for hiding this comment

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

We should generalize this to all error status codes (4xx/5xx). So I think it's better to use this mainRecord.hasErrorStatusCode() block instead of doing a === 404 check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does generalizing this to include all error status codes change our initial thoughts on the defaults? or do they feel good still?

  • devtools - ignore status code
  • node - fail on status code
  • cli - fail on status code
  • etc

Copy link
Member

Choose a reason for hiding this comment

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

I think the defaults should be the same as we discussed

@adrianaixba adrianaixba changed the title core: create flag to warn for a page that returns a 404 core: create flag to only warn when a page returns with an error code Oct 19, 2023
Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

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

Overall looks good!

core/lib/navigation-error.js Outdated Show resolved Hide resolved
core/lib/navigation-error.js Outdated Show resolved Hide resolved
expect(error.message).toEqual('ERRORED_DOCUMENT_REQUEST');
expect(error.code).toEqual('ERRORED_DOCUMENT_REQUEST');
expect(error.friendlyMessage).toBeDisplayString(/^Lighthouse was unable to reliably load.*404/);
expect(error.friendlyMessage).toBeDisplayString(/^Lighthouse was unable to reliably load/);
Copy link
Member

Choose a reason for hiding this comment

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

The 404 is important IMO, otherwise this could pass for one of the non-status code related page load errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would also likely be helpful to add a documentStatusCode (or something similar) to track the result easily pragmatically.

Copy link
Member

Choose a reason for hiding this comment

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

runWarnings only accepts string type currently. I think it would be a larger change to allow extra data fields on warnings. Seems out of scope for this PR.

FWIW the bad status code is also tracked by our http-status-code audit which is easier to track programatically.

@adamraine adamraine changed the title core: create flag to only warn when a page returns with an error code core: create flag to prevent fatal error on bad status code Oct 19, 2023
@adrianaixba adrianaixba merged commit 9832e96 into main Oct 20, 2023
26 checks passed
@adrianaixba adrianaixba deleted the not-found branch October 20, 2023 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to audit 404 (not-found) html page with lighthouse
6 participants