From 737a87378a85a4f55956c5368777dd3cb6f8e8e1 Mon Sep 17 00:00:00 2001 From: harlan Date: Wed, 1 Jan 2025 18:48:04 +1100 Subject: [PATCH] fix(core): handle corrupt cached reports Fixes #255 --- packages/core/src/puppeteer/tasks/lighthouse.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core/src/puppeteer/tasks/lighthouse.ts b/packages/core/src/puppeteer/tasks/lighthouse.ts index cfe81684..6dfb68d9 100644 --- a/packages/core/src/puppeteer/tasks/lighthouse.ts +++ b/packages/core/src/puppeteer/tasks/lighthouse.ts @@ -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)