From f0a1c0805ba108c4ac46a965d6f5011da4bce8d2 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Mon, 31 Aug 2026 14:32:02 +0200 Subject: [PATCH] Never exit non-zero on snapshot or report I/O failures Addresses the review note that 'always exits 0' was not literal: a corrupt base snapshot now degrades to a warning and no diff, and a failed snapshot or markdown write to a warning, so the metric can never fail the build. Co-Authored-By: Claude Fable 5 --- scripts/react-compiler-report.ts | 36 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/scripts/react-compiler-report.ts b/scripts/react-compiler-report.ts index e67d188b78..8385f1b549 100755 --- a/scripts/react-compiler-report.ts +++ b/scripts/react-compiler-report.ts @@ -256,14 +256,30 @@ if (snapshotPath) { [...status].sort(([a], [b]) => a.localeCompare(b)), ), } - writeFileSync(snapshotPath, JSON.stringify(snapshot)) + try { + writeFileSync(snapshotPath, JSON.stringify(snapshot)) + } catch (err) { + console.log( + `::warning::Could not write the snapshot: ${(err as Error).message}`, + ) + } } +/* + * A metric must never fail the build, so an unreadable snapshot just means no + * diff and a warning rather than a non-zero exit. + */ const baseSnapshotPath = process.env.REACT_COMPILER_BASE_SNAPSHOT_PATH -const base: Snapshot | null = - baseSnapshotPath && existsSync(baseSnapshotPath) - ? JSON.parse(readFileSync(baseSnapshotPath, 'utf8')) - : null +let base: Snapshot | null = null +if (baseSnapshotPath && existsSync(baseSnapshotPath)) { + try { + base = JSON.parse(readFileSync(baseSnapshotPath, 'utf8')) + } catch (err) { + console.log( + `::warning::Ignoring unreadable base snapshot: ${(err as Error).message}`, + ) + } +} const lost: StableKey[] = [] const regained: StableKey[] = [] @@ -377,6 +393,12 @@ if (summaryPath || reportPath) { ``, ``, ].join('\n') - if (summaryPath) appendFileSync(summaryPath, markdown) - if (reportPath) writeFileSync(reportPath, markdown) + try { + if (summaryPath) appendFileSync(summaryPath, markdown) + if (reportPath) writeFileSync(reportPath, markdown) + } catch (err) { + console.log( + `::warning::Could not write the markdown report: ${(err as Error).message}`, + ) + } }