Handle gracefully parse errors of checksum cache file

This commit is contained in:
Jerome Prinet
2025-09-10 16:15:18 +02:00
parent c04286a41d
commit e3a87b5ce4
2 changed files with 18 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'
import {ACTION_METADATA_DIR} from '../configuration'
import * as core from '@actions/core'
export class ChecksumCache {
private readonly cacheFile: string
@@ -12,7 +13,11 @@ export class ChecksumCache {
load(): string[] {
// Load previously validated checksums saved in Gradle User Home
if (fs.existsSync(this.cacheFile)) {
return JSON.parse(fs.readFileSync(this.cacheFile, 'utf-8'))
try {
return JSON.parse(fs.readFileSync(this.cacheFile, 'utf-8'))
} catch (e) {
core.warning(`Failed to parse checksum cache file: ${e}`)
}
}
return []
}