Skip to content

Commit 737a873

Browse files
committed
fix(core): handle corrupt cached reports
Fixes #255
1 parent c011378 commit 737a873

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/core/src/puppeteer/tasks/lighthouse.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ export const runLighthouseTask: PuppeteerTask = async (props) => {
9999
// if the report doesn't exist, we're going to run a new lighthouse process to generate it
100100
const reportJsonPath = join(routeReport.artifactPath, ReportArtifacts.reportJson)
101101
if (resolvedConfig.cache && fs.existsSync(reportJsonPath)) {
102-
const report = fs.readJsonSync(reportJsonPath, { encoding: 'utf-8' }) as Result
103-
routeReport.report = normaliseLighthouseResult(routeReport, report)
104-
return routeReport
102+
try {
103+
const report = fs.readJsonSync(reportJsonPath, {encoding: 'utf-8'}) as Result
104+
routeReport.report = normaliseLighthouseResult(routeReport, report)
105+
return routeReport
106+
} catch(e) {
107+
logger.warn(`Failed to read cached lighthouse report for path "${routeReport.route.path}".`, e)
108+
}
105109
}
106110

107111
await setupPage(page)

0 commit comments

Comments
 (0)