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 <noreply@anthropic.com>
This commit is contained in:
@@ -256,14 +256,30 @@ if (snapshotPath) {
|
|||||||
[...status].sort(([a], [b]) => a.localeCompare(b)),
|
[...status].sort(([a], [b]) => a.localeCompare(b)),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
writeFileSync(snapshotPath, JSON.stringify(snapshot))
|
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 baseSnapshotPath = process.env.REACT_COMPILER_BASE_SNAPSHOT_PATH
|
||||||
const base: Snapshot | null =
|
let base: Snapshot | null = null
|
||||||
baseSnapshotPath && existsSync(baseSnapshotPath)
|
if (baseSnapshotPath && existsSync(baseSnapshotPath)) {
|
||||||
? JSON.parse(readFileSync(baseSnapshotPath, 'utf8'))
|
try {
|
||||||
: null
|
base = JSON.parse(readFileSync(baseSnapshotPath, 'utf8'))
|
||||||
|
} catch (err) {
|
||||||
|
console.log(
|
||||||
|
`::warning::Ignoring unreadable base snapshot: ${(err as Error).message}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const lost: StableKey[] = []
|
const lost: StableKey[] = []
|
||||||
const regained: StableKey[] = []
|
const regained: StableKey[] = []
|
||||||
@@ -377,6 +393,12 @@ if (summaryPath || reportPath) {
|
|||||||
`</details>`,
|
`</details>`,
|
||||||
``,
|
``,
|
||||||
].join('\n')
|
].join('\n')
|
||||||
|
try {
|
||||||
if (summaryPath) appendFileSync(summaryPath, markdown)
|
if (summaryPath) appendFileSync(summaryPath, markdown)
|
||||||
if (reportPath) writeFileSync(reportPath, markdown)
|
if (reportPath) writeFileSync(reportPath, markdown)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(
|
||||||
|
`::warning::Could not write the markdown report: ${(err as Error).message}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user