Skip to content

Commit

Permalink
core: report artifact error when collected, add err.extra (#15258)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Jul 14, 2023
1 parent 376db8f commit bef3df9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 9 additions & 1 deletion core/gather/runner-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import log from 'lighthouse-logger';

import {Sentry} from '../lib/sentry.js';

/**
*
* @param {{id: string}} dependency
Expand Down Expand Up @@ -115,7 +117,13 @@ async function collectPhaseArtifacts(options) {
return artifact;
});

await artifactPromise.catch(() => {});
await artifactPromise.catch((err) => {
Sentry.captureException(err, {
tags: {gatherer: artifactDefn.id, phase},
level: 'error',
});
log.error(artifactDefn.id, err.message);
});
artifactState[phase][artifactDefn.id] = artifactPromise;
}
}
Expand Down
11 changes: 9 additions & 2 deletions core/lib/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ async function init(opts) {
if (opts.tags) {
scope.setTags(opts.tags);
}
if (opts.extra) {
scope.setExtras(opts.extra);

// Add extra details
let extra;
if (opts.extra) extra = {...opts.extra};
// @ts-expect-error Non-standard property
if (err.extra) extra = {...extra, ...err.extra};
if (extra) {
scope.setExtras(extra);
}

Sentry.captureException(err);
});
};
Expand Down
8 changes: 2 additions & 6 deletions core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,11 @@ class Runner {
// @ts-expect-error: TODO why is this a type error now?
const artifactError = artifacts[artifactName];

Sentry.captureException(artifactError, {
tags: {gatherer: artifactName},
level: 'error',
});

log.warn('Runner', `${artifactName} gatherer, required by audit ${audit.meta.id},` +
` encountered an error: ${artifactError.message}`);

// Create a friendlier display error and mark it as expected to avoid duplicates in Sentry
// Create a friendlier display error and mark it as expected to avoid duplicates in Sentry.
// The artifact error was already sent to Sentry in `collectPhaseArtifacts`.
const error = new LighthouseError(LighthouseError.errors.ERRORED_REQUIRED_ARTIFACT,
{artifactName, errorMessage: artifactError.message}, {cause: artifactError});
// @ts-expect-error Non-standard property added to Error
Expand Down

0 comments on commit bef3df9

Please sign in to comment.