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

Update Manifest gatherer to use gather error instead of -1 artifact #1624

Merged
merged 3 commits into from
Feb 8, 2017

Conversation

brendankenny
Copy link
Member

@brendankenny brendankenny commented Feb 3, 2017

Part of #941. There a lot of audits that depend on the manifest gatherer, so separated this one from #1623.

The most impactful change I made was to make the manifest gatherer return null if the page has no manifest as it seems appropriate to have an explicit value for this (and obviously not having a manifest is not an error).

This sticks to the minimal redundancy of debugStrings that #1598 started: if the page has no manifest, all the manifest audits will fail with no message. If the manifest was there but invalid JSON, they will all fail but only manifest-exists will report the debugString.

There's a good bit of redundancy here. It may make sense to split these into their own audits/ subdirectory a la accessibility/ and do some kind of base class thing (and unify testing...most of these tests are duplicates with only the tested property changed)

}

return Manifest._errorManifest(errorString);
// The driver will return an empty string for url and the data if
Copy link
Member

Choose a reason for hiding this comment

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

i'd keep this comment above the if (response.url) conditional

Copy link
Member Author

Choose a reason for hiding this comment

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

hopefully clarified the comment

* Returns the parsed manifest or null, if the page had no manifest.
* @param {!Object} options
* @return {!Promise<?Manifest>}
*/
afterPass(options) {
return options.driver.sendCommand('Page.getAppManifest')
.then(response => {
// We're not reading `response.errors` however it may contain critical and noncritical
Copy link
Member

Choose a reason for hiding this comment

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

wdyt about handling these? it might help us differentiate between bad JSON, missing, or other issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

wdyt about handling these?

do we have a bug tracking it? I assume you added that comment :)

it might help us differentiate between bad JSON, missing, or other issues.

the first two should be handled, but yeah, other issues would be good to catch

Copy link
Member

@paulirish paulirish Feb 8, 2017

Choose a reason for hiding this comment

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

do we have a bug tracking it? I assume you added that comment :)

lookie lookie: #823

OHHHHHHHHHHHHHHHHHH WHAT NOW

const cacheContents = artifacts.CacheContents;

if (!(manifest && manifest.start_url && manifest.start_url.value)) {
if (!artifacts.Manifest || !artifacts.Manifest.value) {
Copy link
Member

Choose a reason for hiding this comment

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

Since artifacts.Manifest is now null in the non-exist case, should we just change all these to this?

if (artifacts.Manifest === null) {

Copy link
Member Author

Choose a reason for hiding this comment

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

this is checking two error states.

  1. no manifest, so the artifacts.Manifest is null. This could do the explicit check, but not sure if it's worth it as the gatherer will only return null or an object, so only null will be falsy.

  2. invalid JSON, so artifacts.Manifest.value will be undefined. Invalid JSON is the only way that artifacts.Manifest.value, but we have to check for it.

    One solution I considered to get rid of the extra check was to throw if the JSON was invalid, but it felt a bit weird to declare a gatherer error when it really was an error in the user's data. It would also mean that every manifest audit would have a debugString of Audit error: Manifest gatherer encountered an error: invalid JSON (or whatever) . That's a lot of visual noise when it could just be on the manifest-exists audit as it is here. OTOH, invalid JSON in your manifest is a pretty big and obvious error and one the site owner should fix quickly, so maybe that's fine.

Copy link
Member

Choose a reason for hiding this comment

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

well i guess i'm saying we should handle the invalid JSON case via response.errors in the gatherer, so we can be more clear here. otherwise these are the only audits that have to differentiate between two error states (plus they can't say which they're in)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, maybe I don't understand what you're saying.

Just to be clear, by invalid JSON I mean just unparseable JSON; if the manifest is parseable by JSON.parse but is invalid according to the manifest spec, that will show up in the individual audits.

This code can separate these two states, but I put them in one conditional on purpose because we want the audits to just fail and not output a debugString (otherwise we'd have 12 debugStrings or whatever in the report saying the same thing).

@@ -40,6 +40,13 @@ class ManifestExists extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (!artifacts.Manifest) {
Copy link
Member

Choose a reason for hiding this comment

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

compare against null?

Copy link
Member Author

Choose a reason for hiding this comment

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

compare against null?

as above, we can compare against null if you feel strongly about it, but null is the only falsy value you could get here (and if we added the check against null specifically and let through the other falsy values, artifacts.Manifest.value below would throw anyways)

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

We talked this one out a bit. A few more things but i trust it'll be good.

@brendankenny brendankenny merged commit 9f91ab4 into master Feb 8, 2017
@brendankenny brendankenny deleted the manifest branch February 8, 2017 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants