Skip to content

Commit

Permalink
fix(core): handle corrupt cached reports
Browse files Browse the repository at this point in the history
Fixes #255
  • Loading branch information
harlan-zw committed Jan 1, 2025
1 parent c011378 commit 737a873
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/puppeteer/tasks/lighthouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ export const runLighthouseTask: PuppeteerTask = async (props) => {
// if the report doesn't exist, we're going to run a new lighthouse process to generate it
const reportJsonPath = join(routeReport.artifactPath, ReportArtifacts.reportJson)
if (resolvedConfig.cache && fs.existsSync(reportJsonPath)) {
const report = fs.readJsonSync(reportJsonPath, { encoding: 'utf-8' }) as Result
routeReport.report = normaliseLighthouseResult(routeReport, report)
return routeReport
try {
const report = fs.readJsonSync(reportJsonPath, {encoding: 'utf-8'}) as Result
routeReport.report = normaliseLighthouseResult(routeReport, report)
return routeReport
} catch(e) {
logger.warn(`Failed to read cached lighthouse report for path "${routeReport.route.path}".`, e)
}
}

await setupPage(page)
Expand Down

0 comments on commit 737a873

Please sign in to comment.