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

Start using errors instead of -1 for error artifacts #1560

Merged
merged 4 commits into from
Jan 31, 2017
Merged

Conversation

brendankenny
Copy link
Member

retrying #1498 (as next step of #941), now with errors from gatherers being considered recoverable by default. If you want to stop a run, throw an error with a fatal property set to true.

Biggest benefit is that if something throws inside a gatherer that isn't something the gatherer cares about or is specifically watching for, it can just let the exception go. That means

  • no more catch block in every gatherer
  • no more -1 artifacts...now they're just Error objects
  • no more checking for -1 artifacts in every audit. If one of an audit's requiredArtifacts is an error, the audit never runs and LH emits an error result on behalf of that audit.

First commits changes old recoverable infra to support fatal.
Other commits try switching over some of our gatherers to using this format. The first two (meta viewport and theme-color) are simple, the last commit is giving that treatment to the slightly more complicated Styles and CSSUsage gatherers and the two audits that need them.

Thoughts?

@brendankenny
Copy link
Member Author

brendankenny commented Jan 27, 2017

screen shot 2017-01-27 at 15 48 14
and that's just four audits :D

@@ -29,8 +29,7 @@ class CSSUsage extends Gatherer {
.catch(err => {
// TODO(phulce): Remove this once CSS usage hits stable
if (/startRuleUsageTracking/.test(err.message)) {
this.failure = 'CSS Usage tracking requires Chrome \u2265 56';
return;
throw new Error('CSS Usage tracking requires Chrome \u2265 56');
Copy link
Member Author

Choose a reason for hiding this comment

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

@patrickhulce now that errors are non-fatal by default, afterPass still throws but this error wins

Copy link
Collaborator

Choose a reason for hiding this comment

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

cool beans

@paulirish
Copy link
Member

Looks nice so far!

Do we have a location where we'd quit on a fatal error? Would love to see that in action.

@brendankenny
Copy link
Member Author

Do we have a location where we'd quit on a fatal error

What do you mean? Like a test run really quits? We don't have any gatherer that throws a fatal error yet :) (and I'm not entirely sure what would warrant doing that at this point)

The "rejects if a gatherer returns a fatal error" test in gather-runner-test checks that gather-runner throws if a gatherer returns a fatal error, though.

@brendankenny
Copy link
Member Author

yah? nah?


// If artifact was an error, it must be non-fatal (or gatherRunner would
// have thrown). Output error result on behalf of audit.
if (artifacts[artifactName] instanceof Error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any of the same machinery for audits? Or are we still treating all errors there as fatal?

Copy link
Member Author

Choose a reason for hiding this comment

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

Any of the same machinery for audits? Or are we still treating all errors there as fatal?

we can. There's no reason we can't also get rid of generateAuditResult({rawValue: -1, debugString: 'whatever'}) and just let audits throw errors and teach the reporter(s) to handle output for those cases

* @param {!Promise<*>} promise
* @return {!Promise<*>}
*/
static recoverOrThrow(promise) {
return promise.catch(err => {
if (!err.recoverable) {
if (err.fatal) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any of the same machinery for audits? Or are we still treating all errors there as fatal?

@patrickhulce
Copy link
Collaborator

Nice I like this direction a lot!! Can't wait to get that tracking threaded through...

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

LGTM. This is actually fairly low-key :)

Onward and upward with the rest.

@brendankenny
Copy link
Member Author

LGTM. This is actually fairly low-key

indeed :)

@brendankenny
Copy link
Member Author

brendankenny commented Jan 31, 2017

LGTY? I was planning on merging and doing these in chunks so I don't have to keep rebasing :)

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

Yea, let's get this in so you're not blocked.

@brendankenny brendankenny merged commit e225142 into master Jan 31, 2017
@brendankenny brendankenny deleted the gathererrors branch January 31, 2017 02:12
@brendankenny
Copy link
Member Author

👍

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

4 participants