Skip to content

Commit

Permalink
Log exceptions to CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Apr 25, 2017
1 parent b25f535 commit 7d81c96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lighthouse-core/gather/gather-runner.js
Expand Up @@ -132,10 +132,12 @@ class GatherRunner {
* Test any error output from the promise, absorbing non-fatal errors and
* throwing on fatal ones so that run is stopped.
* @param {!Promise<*>} promise
* @param {!string} gathererName
* @return {!Promise<*>}
*/
static recoverOrThrow(promise) {
static recoverOrThrow(promise, gathererName) {
return promise.catch(err => {
log.warn(gathererName, `Caught exception: ${err.message}`);
if (err.fatal) {
throw err;
}
Expand Down Expand Up @@ -178,7 +180,7 @@ class GatherRunner {
return chain.then(_ => {
const artifactPromise = Promise.resolve().then(_ => gatherer.beforePass(options));
gathererResults[gatherer.name] = [artifactPromise];
return GatherRunner.recoverOrThrow(artifactPromise);
return GatherRunner.recoverOrThrow(artifactPromise, gatherer.name);
});
}, pass);
}
Expand All @@ -196,8 +198,8 @@ class GatherRunner {
const gatherers = config.gatherers;

const gatherernames = gatherers.map(g => g.name).join(', ');
const status = 'Loading page & waiting for onload';
log.log('status', status, gatherernames);
const status = 'Loading page & waiting for idle';
log.log('status', status, `Collecting data for ${gatherernames}`);

const pass = GatherRunner.loadPage(driver, options).then(_ => {
log.log('statusEnd', status);
Expand All @@ -207,7 +209,7 @@ class GatherRunner {
return chain.then(_ => {
const artifactPromise = Promise.resolve().then(_ => gatherer.pass(options));
gathererResults[gatherer.name].push(artifactPromise);
return GatherRunner.recoverOrThrow(artifactPromise);
return GatherRunner.recoverOrThrow(artifactPromise, gatherer.name);
});
}, pass);
}
Expand Down Expand Up @@ -264,7 +266,7 @@ class GatherRunner {
log.log('status', status);
const artifactPromise = Promise.resolve().then(_ => gatherer.afterPass(options, passData));
gathererResults[gatherer.name].push(artifactPromise);
return GatherRunner.recoverOrThrow(artifactPromise);
return GatherRunner.recoverOrThrow(artifactPromise, gatherer.name);
}).then(_ => {
log.verbose('statusEnd', status);
});
Expand Down
9 changes: 9 additions & 0 deletions lighthouse-core/runner.js
Expand Up @@ -93,6 +93,12 @@ class Runner {
return artifacts;
});


run = run.then(artifacts => {
log.log('status', 'Analyzing and running audits...');
return artifacts;
});

// Run each audit sequentially, the auditResults array has all our fine work
const auditResults = [];
for (const audit of config.audits) {
Expand Down Expand Up @@ -125,6 +131,8 @@ class Runner {
// Format and aggregate results before returning.
run = run
.then(runResults => {
log.log('status', 'Generating results...');

const resultsById = runResults.auditResults.reduce((results, audit) => {
results[audit.name] = audit;
return results;
Expand Down Expand Up @@ -202,6 +210,7 @@ class Runner {
// Fill remaining audit result fields.
}).then(auditResult => Audit.generateAuditResult(audit, auditResult))
.catch(err => {
log.warn(audit.meta.name, `Caught exception: ${err.message}`);
if (err.fatal) {
throw err;
}
Expand Down

0 comments on commit 7d81c96

Please sign in to comment.